From 7039d08976e6decf4d353851ec1d1d51f454590b Mon Sep 17 00:00:00 2001 From: piyush Date: Mon, 30 Oct 2023 14:16:32 +0530 Subject: [PATCH] vv --- Quiz App/script.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Quiz App/script.js b/Quiz App/script.js index c13cc1d..437b81b 100644 --- a/Quiz App/script.js +++ b/Quiz App/script.js @@ -53,16 +53,17 @@ const showQuestions = () => { choicesBox.appendChild(choiceDiv); choiceDiv.addEventListener('click', () => { - if (choiceDiv.classList.contains('selected')) { - choiceDiv.classList.remove('selected'); - } - else { - choiceDiv.classList.add('selected'); - } + // Deselect all choices + const allChoices = document.querySelectorAll('.choice'); + allChoices.forEach((choice) => { + choice.classList.remove('selected'); + }); + + // Select the clicked choice + choiceDiv.classList.add('selected'); }); } - - if(currentQuestionIndex < quiz.length){ + if(currentQuestionIndex < quiz.length){ startTimer(); } }