${q.options.map((opt, index) => `${opt}
`).join('')}
`; } function selectOption(selected) { const correct = quizData[currentQuestion].answer; if (selected === correct) { score++; } const options = document.querySelectorAll('.option-strip'); options.forEach((opt, idx) => { opt.style.pointerEvents = "none"; if (idx === correct) opt.style.background = "#c8f7c5"; else if (idx === selected) opt.style.background = "#f7c5c5"; }); } function nextQuestion() { currentQuestion++; if (currentQuestion < quizData.length) { loadQuestion(); } else { showResult(); } } function showResult() { const percentage = (score / quizData.length) * 100; let emoji = ''; if (percentage >= 90) { emoji = '🎉 Excellent!'; } else if (percentage >= 60) { emoji = '🙂 Good Job!'; } else { emoji = '🙁 Needs Improvement.'; } quizContainer.innerHTML = ` Quiz Completed!
You got ${score} out of ${quizData.length} correct.
${percentage}%
${emoji}
`; } function restartQuiz() { score = 0; currentQuestion = 0; loadQuestion(); } // Start quiz loadQuestion();Related