From 0f4462bf4cad06b45a42c09bed1e015e6f55d7d7 Mon Sep 17 00:00:00 2001 From: SkyEye_FAST Date: Fri, 12 Jul 2024 00:08:59 +0800 Subject: [PATCH] Try to fix #9 --- static/js/quiz.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/static/js/quiz.js b/static/js/quiz.js index 83adca1..4db3ff1 100644 --- a/static/js/quiz.js +++ b/static/js/quiz.js @@ -1,10 +1,15 @@ $(document).ready(function () { let currentQuestionIndex = 0; - const questions = questionsData; + const questions = questionsData || {}; const questionKeys = Object.keys(questions); const delayBetweenQuestions = 800; const fadeDuration = 300; + if (questionKeys.length === 0) { + console.error("No questions available."); + return; + } + function createBoxes(length) { const boxesDiv = $("#boxes").empty(); for (let i = 0; i < length; i++) { @@ -16,11 +21,6 @@ $(document).ready(function () { } function loadQuestion() { - if (currentQuestionIndex >= questionKeys.length) { - showSummary(); - return; - } - $("#inputBox").val(""); const currentKey = questionKeys[currentQuestionIndex]; @@ -91,12 +91,18 @@ $(document).ready(function () { const correctAnswer = questions[currentKey].translation; if (input === correctAnswer) { + currentQuestionIndex++; + + console.log("当前题目索引:", currentQuestionIndex); + console.log("当前键名:", currentKey); + Sentry.captureMessage(`Quiz, ${currentQuestionIndex}`); + setTimeout(() => { - currentQuestionIndex++; - console.log("当前题目索引:", currentQuestionIndex); - console.log("当前键名:", currentKey); - Sentry.captureMessage(`Quiz, ${currentQuestionIndex}`); - loadQuestion(); + if (currentQuestionIndex < questionKeys.length) { + loadQuestion(); + } else { + showSummary(); + } }, delayBetweenQuestions); } });