diff --git a/js/timer.js b/js/timer.js new file mode 100644 index 0000000..f8ce5c7 --- /dev/null +++ b/js/timer.js @@ -0,0 +1,42 @@ +// Timer module + +export class Timer { + constructor(timeLimit, timerElementId, callback) { + this.timeLimit = timeLimit; // Time in seconds + this.timeLeft = timeLimit; // Time left in seconds + this.timerElement = document.getElementById(timerElementId); // The DOM element to display the timer + this.callback = callback; // Function to call when time is up + this.timerInterval = null; // To store the interval ID + } + + // Start the timer + start() { + this.timeLeft = this.timeLimit; + this.updateDisplay(); + + this.timerInterval = setInterval(() => { + this.timeLeft--; + this.updateDisplay(); + + if (this.timeLeft <= 0) { + this.stop(); + if (this.callback) { + this.callback(); // Call the callback function when time runs out + } + } + }, 1000); + } + + // Stop the timer + stop() { + clearInterval(this.timerInterval); + } + + // Update the timer display on the page + updateDisplay() { + if (this.timerElement) { + this.timerElement.textContent = `${this.timeLeft}s`; + } + } + } + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 262a549..1f1d76c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,3 +1,12 @@ { - "version": "8.0.1" - } + "name": "quiz_OPENSOURCEPROJECT-1", + "version": "8.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "quiz_OPENSOURCEPROJECT-1", + "version": "8.0.1" + } + } +} diff --git a/pages/youtube/game.html b/pages/youtube/game.html index e6723e4..4249a63 100644 --- a/pages/youtube/game.html +++ b/pages/youtube/game.html @@ -9,24 +9,43 @@ integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous" /> - - - Quiz Page - YouTube + + Quiz Page - Main Game + + @@ -45,14 +64,19 @@

Score

0

-

-

-100

+
+ +
+

Time Left

+

30s

+ +

What is the answer to this question

A

-

Choice

+

Choice 1

B