Skip to content

Commit 27349f1

Browse files
committed
commit
1 parent b7d3f81 commit 27349f1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

assets/javascript/game.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
var url = "https://opentdb.com/api.php";
22
var ticker;
3+
var tickerTwo;
34
var iterator = 0;
4-
var timer_is_on = 0;
5+
var correct;
6+
var wrong;
7+
58
$("#modal-btn").on("click", function () {
69
console.log("clicked");
710
url += "?" + $.param({
@@ -28,7 +31,7 @@ $("#modal-btn").on("click", function () {
2831
var ansArr = [];
2932
var randomizedArr = [];
3033
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-
34+
3235
while (ansArr.length > 0) {
3336
var randIndex = Math.floor(Math.random() * ansArr.length);
3437
var removed = ansArr.splice(randIndex, 1);
@@ -45,6 +48,7 @@ $("#modal-btn").on("click", function () {
4548
console.log('clicked again');
4649
if ($(this).html() == response.results[iterator].correct_answer) {
4750
$("#display").html('correct!');
51+
clearTimeout(tickerTwo);
4852
clearTimeout(ticker);
4953
iterator++;
5054
setTimeout(() => {
@@ -55,6 +59,7 @@ $("#modal-btn").on("click", function () {
5559

5660
} else {
5761
$("#display").html('wrong!');
62+
clearTimeout(tickerTwo);
5863
clearTimeout(ticker);
5964
iterator++;
6065
setTimeout(() => {
@@ -67,11 +72,15 @@ $("#modal-btn").on("click", function () {
6772

6873
function timer(t) {
6974
questionGenerator();
75+
tickerTwo = setTimeout(() => {
76+
$("#display").html('took too long!');
77+
}, t);
7078
ticker = setTimeout(() => {
79+
$("#display").empty();
7180
iterator++;
7281
questionGenerator();
7382
timer(20000);
74-
}, t);
83+
}, t + 2000);
7584
};
7685
timer(20000);
7786
// questionGenerator();

0 commit comments

Comments
 (0)