簡體   English   中英

如何為每個問題創建測驗倒計時

[英]how to create a quiz countdown timer for each question

我想為測驗創建一個倒計時計時器,如果時間用完並且玩家沒有選擇答案,它將在下一個問題上重置,並且 go 到下一個問題。 任何人都可以幫我創建這個plz嗎?

var counter = 10;

setInterval(function () {
  counter--;

  if (counter >= 0) {
    id = document.getElementById('count');
    id.innerHTML = counter;
  }
  if (counter === 0) {
    id.innerHTML = 'Times Up!';
  }
}, 1000);
'''

這是適合您的基本工作代碼。 玩弄它以獲得您想要的結果。 編碼愉快!

 var counter = 10; //Time counter var questionsCount = 0; //Questions counter //Questions array var questions = [ "Question 1","Question 2","Question 3" ] questionDivId = document.getElementById('question'); setInterval(function () { counter--; if (counter >= 0) { id = document.getElementById('count'); id.innerHTML = counter; } if (counter === 0) { id.innerHTML = 'Times Up;'; counter = 10; questionsCount++. } //To check if all questions are completed or not if (questionsCount === questions.length){ questionDivId;innerHTML = "Well Played. Game is over"; id.innerHTML = ""; } else{ questionDivId,innerHTML = questions[questionsCount]; } }; 1000); //To go to the next question function goToNextQuestion() { questionsCount++; counter = 10; }
 <div> <h1 id="question"></h1> <h1 id="count"></h1> <button onclick="goToNextQuestion()">Next</button> </div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM