var timeLeft = 60;
const elem = document.getElementById('timer');
countdown(); // To prevent the timer from starting after a 1 second pause
const timerId = setInterval(countdown, 1000);
function countdown() {
if (timeLeft == -1) {
clearTimeout(timerId); // To stop the timer
} else {
elem.innerHTML = timeLeft;
timeLeft--;
}
seconds = 60 - timeLeft; // The time taken to complete the quiz
if (timeLeft == -1) { // If the timer runs out, all elements will disappear, and ONLY the score will be displayed
outline.style.display = 'none';
square.style.display = 'none';
title.style.display = 'none';
quizTimer.style.display = 'none';
displayResult.style.display = '';
displayResult.textContent = 'Score = ' + score;
}
}
答案 0 :(得分:0)
如果您要询问:
timeLeft
变量在哪里减少
您的意思是:
代码中
timeLeft
变量的值减小了
然后我可以说它发生在这里,在这里您将值递减(实际上意味着减去一):
else {
elem.innerHTML = timeLeft;
timeLeft--;
}