Skip to content

Commit

Permalink
Try to fix #8
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyEye-FAST committed Jul 13, 2024
1 parent 4cb504c commit 582fe42
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions static/js/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ $(document).ready(function () {
updateBoxes();
});

$inputBox.on("input", function () {
$inputBox.on("input", async function () {
const input = $(this).val();
const currentKey = questionKeys[currentQuestionIndex];
const { translation } = questionsData[currentKey];
Expand All @@ -150,19 +150,29 @@ $(document).ready(function () {
}

if (input === translation) {
await delay(delayBetweenQuestions);
if (currentQuestionIndex === questionKeys.length - 1) {
setTimeout(showSummary, delayBetweenQuestions);
showSummary();
} else {
setTimeout(() => {
$info.fadeOut(fadeDuration, function () {
currentQuestionIndex++;
initializeQuestion();
});
}, delayBetweenQuestions);
await fadeOutInfo(fadeDuration);
currentQuestionIndex++;
initializeQuestion();
}
}
});

function delay(duration) {
return new Promise(resolve => setTimeout(resolve, duration));
}

function fadeOutInfo(fadeDuration) {
return new Promise(resolve => {
$info.fadeOut(fadeDuration, function () {
resolve();
});
});
}

// Initialize first question
initializeQuestion();
});
Expand Down

0 comments on commit 582fe42

Please sign in to comment.