diff --git a/js/QuizClass.js b/js/QuizClass.js index a065629..af6ec40 100644 --- a/js/QuizClass.js +++ b/js/QuizClass.js @@ -80,6 +80,12 @@ export class Quiz { console.log("Total Correct:", this.TOTAL_CORRECT); } + showTimeoutDialog() { + alert("Time's up!"); + + this._endGame(); + } + checkAnswer(selected = 0, correct = 0) { const p = document.querySelector(`[data-number="${selected}"]`); diff --git a/pages/game.html b/pages/game.html index 657b1be..48c5eb0 100644 --- a/pages/game.html +++ b/pages/game.html @@ -28,6 +28,27 @@ ); } }); + + const timerDuration = 30; + + function startTimer() { + let timeLeft = timerDuration; + const timerElement = document.getElementById("timer"); + + const timerInterval = setInterval(() => { + timeLeft--; + timerElement.textContent = timeLeft; + + if (timeLeft <= 0) { + clearInterval(timerInterval); + QuizInstance.showTimeoutDialog(); + } + }, 1000); + } + + + + document.addEventListener("DOMContentLoaded", startTimer); @@ -41,6 +62,10 @@
+
+

Timer

+

30

+

Score

0