`; }); document.getElementById('optionsBox').innerHTML = optionsHtml; document.getElementById('nextBtn').style.display = "none"; const progress = document.getElementById('progress'); const progressBar = document.getElementById('progress-bar-inner'); progress.textContent = `${currentQuestionIndex + 1}/${questions.length}`; progressBar.style.width = `${((currentQuestionIndex + 1) / questions.length) * 100}%`; } function selectOption(selectedIndex) { const question = questions[currentQuestionIndex]; const options = document.querySelectorAll('.option'); options.forEach((option, index) => { option.classList.add('disabled'); if (index === selectedIndex) { option.classList.add(index === question.answer ? 'correct' : 'incorrect'); } if (index === question.answer) { option.classList.add('correct'); } }); score += selectedIndex === question.answer ? 1 : 0; document.getElementById('nextBtn').style.display = "flex"; } function goToNext() { if (currentQuestionIndex < questions.length - 1) { currentQuestionIndex++; showQuestion(); } else { showResult(); } } function showResult() { document.getElementById('questionBox').style.display = "none"; document.getElementById('optionsBox').style.display = "none"; document.getElementById('nextBtn').style.display = "none"; document.getElementById('progress').style.display = "none"; document.getElementById('result').innerHTML = ` 🎯 You scored ${score}/${questions.length}
${score >= 8 ? "🎉 Excellent!" : score >= 5 ? "👍 Good try!" : "😕 Keep practicing!"}
`; } showQuestion(); Related