Skip to content
Snippets Groups Projects
Commit 55606592 authored by enr27's avatar enr27
Browse files

Replace script.js

parent f058f0d5
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment