} } function showQuizResults(res) { // Show feedback on each question res.details.forEach(detail => { const block = document.getElementById('qblock_' + detail.question_id); const fb = document.getElementById('feedback_' + detail.question_id); const options = block.querySelectorAll('.quiz-option'); // Disable all inputs block.querySelectorAll('input[type=radio]').forEach(i => i.disabled = true); // Mark each option options.forEach(opt => { const optLetter = opt.dataset.opt; if (optLetter === detail.correct) { opt.classList.add('correct'); } else if (optLetter === detail.given && !detail.is_correct) { opt.classList.add('incorrect'); } }); // Show explanation fb.style.display = 'block'; fb.innerHTML = `${detail.is_correct ? '✓ Correct!' : '✗ Incorrect'} ${escHtml(detail.explanation)}`; }); // Show results panel const pct = res.percentage; const circle = document.getElementById('scoreCircle'); circle.textContent = res.score + '/' + res.total; circle.className = 'quiz-score-circle ' + (pct >= 80 ? 'score-gold' : pct >= 60 ? 'score-silver' : 'score-bronze'); const label = document.getElementById('resultLabel'); const msg = document.getElementById('resultMsg'); if (pct === 100) { label.textContent = '🏆 Perfect Score!'; msg.textContent = 'Outstanding! You have mastered this event completely.'; } else if (pct >= 80) { label.textContent = '🌟 Excellent Work!'; msg.textContent = 'Great understanding of this significant event.'; } else if (pct >= 60) { label.textContent = '👍 Good Effort!'; msg.textContent = 'You have a solid grasp — review the reading to improve further.'; } else { label.textContent = '📖 Keep Studying!'; msg.textContent = 'Review the reading material and try again to strengthen your knowledge.'; } // Scroll to results const resultsPanel = document.getElementById('quizResults'); resultsPanel.style.display = 'block'; document.getElementById('quizForm').querySelector('.quiz-submit-row').style.display = 'none'; setTimeout(() => resultsPanel.scrollIntoView({ behavior: 'smooth', block: 'start' }), 100); } function retryQuiz() { location.href = '/events.php?id=' + QUIZ_ID + '&view=quiz'; } function escHtml(str) { return str.replace(/&/g,'&').replace(//g,'>').replace(/"/g,'"'); }