From 556065925a997cd293c9d31153bbcf7e4712e2ec Mon Sep 17 00:00:00 2001
From: enr27 <enr27@drexel.edu>
Date: Sun, 24 Nov 2024 03:02:34 +0000
Subject: [PATCH] Replace script.js

---
 public/script.js | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/public/script.js b/public/script.js
index efc9918..eab5ec9 100644
--- a/public/script.js
+++ b/public/script.js
@@ -87,6 +87,27 @@ function displayQuestion(question) {
         btn.addEventListener('click', () => checkAnswer(answer, question.correctAnswer));
         optionsContainer.appendChild(btn);
     });
+
+    startTimer(60);
+}
+
+function startTimer(seconds) {
+    const timerElement = document.getElementById('timer');
+    let timeLeft = seconds;
+
+    const updateTimer = () => {
+        if (timeLeft > 0) {
+            timerElement.textContent = `Time left: ${timeLeft} seconds`;
+            timeLeft--;
+        } else {
+            timerElement.textContent = `Time's up!`;
+            socket.emit('nextQuestion', roomCode); 
+            clearInterval(timerInterval); 
+        }
+    };
+
+    updateTimer(); 
+    const timerInterval = setInterval(updateTimer, 1000);
 }
 
 function checkAnswer(selectedAnswer, correctAnswer) {
@@ -140,3 +161,4 @@ function updateUrlWithParams(params) {
     });
     window.history.pushState({}, '', currentUrl); 
 }
+
-- 
GitLab