Skip to content

Commit b7d3f81

Browse files
committed
commit
1 parent f59ac4a commit b7d3f81

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

assets/javascript/game.js

+18-19
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ $("#modal-btn").on("click", function () {
2828
var ansArr = [];
2929
var randomizedArr = [];
3030
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+
3132
while (ansArr.length > 0) {
3233
var randIndex = Math.floor(Math.random() * ansArr.length);
3334
var removed = ansArr.splice(randIndex, 1);
@@ -38,44 +39,42 @@ $("#modal-btn").on("click", function () {
3839
$("#answer2").html(randomizedArr[1]);
3940
$("#answer3").html(randomizedArr[2]);
4041
$("#answer4").html(randomizedArr[3]);
41-
42-
43-
4442
};
43+
4544
$(".answers").on('click', function () {
4645
console.log('clicked again');
4746
if ($(this).html() == response.results[iterator].correct_answer) {
4847
$("#display").html('correct!');
49-
// clearTimeout(ticker);
48+
clearTimeout(ticker);
5049
iterator++;
5150
setTimeout(() => {
52-
// timer(20000);
51+
timer(20000);
5352
$("#display").empty();
54-
questionGenerator();
53+
// questionGenerator();
5554
}, 1200);
5655

5756
} else {
5857
$("#display").html('wrong!');
59-
// clearTimeout(ticker);
58+
clearTimeout(ticker);
6059
iterator++;
6160
setTimeout(() => {
62-
// timer(20000);
61+
timer(20000);
6362
$("#display").empty();
64-
questionGenerator();
63+
// questionGenerator();
6564
}, 1200);
6665
}
6766
})
68-
// function timer(t) {
6967

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();
7978

8079

8180

0 commit comments

Comments
 (0)