@@ -28,6 +28,7 @@ $("#modal-btn").on("click", function () {
28
28
var ansArr = [ ] ;
29
29
var randomizedArr = [ ] ;
30
30
ansArr . push ( response . results [ iterator ] . incorrect_answers [ 0 ] , response . results [ iterator ] . incorrect_answers [ 1 ] , response . results [ iterator ] . incorrect_answers [ 2 ] , response . results [ iterator ] . correct_answer ) ;
31
+
31
32
while ( ansArr . length > 0 ) {
32
33
var randIndex = Math . floor ( Math . random ( ) * ansArr . length ) ;
33
34
var removed = ansArr . splice ( randIndex , 1 ) ;
@@ -38,44 +39,42 @@ $("#modal-btn").on("click", function () {
38
39
$ ( "#answer2" ) . html ( randomizedArr [ 1 ] ) ;
39
40
$ ( "#answer3" ) . html ( randomizedArr [ 2 ] ) ;
40
41
$ ( "#answer4" ) . html ( randomizedArr [ 3 ] ) ;
41
-
42
-
43
-
44
42
} ;
43
+
45
44
$ ( ".answers" ) . on ( 'click' , function ( ) {
46
45
console . log ( 'clicked again' ) ;
47
46
if ( $ ( this ) . html ( ) == response . results [ iterator ] . correct_answer ) {
48
47
$ ( "#display" ) . html ( 'correct!' ) ;
49
- // clearTimeout(ticker);
48
+ clearTimeout ( ticker ) ;
50
49
iterator ++ ;
51
50
setTimeout ( ( ) => {
52
- // timer(20000);
51
+ timer ( 20000 ) ;
53
52
$ ( "#display" ) . empty ( ) ;
54
- questionGenerator ( ) ;
53
+ // questionGenerator();
55
54
} , 1200 ) ;
56
55
57
56
} else {
58
57
$ ( "#display" ) . html ( 'wrong!' ) ;
59
- // clearTimeout(ticker);
58
+ clearTimeout ( ticker ) ;
60
59
iterator ++ ;
61
60
setTimeout ( ( ) => {
62
- // timer(20000);
61
+ timer ( 20000 ) ;
63
62
$ ( "#display" ) . empty ( ) ;
64
- questionGenerator ( ) ;
63
+ // questionGenerator();
65
64
} , 1200 ) ;
66
65
}
67
66
} )
68
- // function timer(t) {
69
67
70
- // questionGenerator();
71
- // ticker = setTimeout(() => {
72
- // iterator++;
73
- // questionGenerator();
74
- // timer(20000);
75
- // }, t);
76
- // };
77
- // timer(20000);
78
- questionGenerator ( ) ;
68
+ function timer ( t ) {
69
+ questionGenerator ( ) ;
70
+ ticker = setTimeout ( ( ) => {
71
+ iterator ++ ;
72
+ questionGenerator ( ) ;
73
+ timer ( 20000 ) ;
74
+ } , t ) ;
75
+ } ;
76
+ timer ( 20000 ) ;
77
+ // questionGenerator();
79
78
80
79
81
80
0 commit comments