EXAM

MCQ Quiz
Touch-friendly buttons. No horizontal scrolling. Cards scale for mobile.
TAG // Replace the results button functionality document.getElementById(‘results-btn’).addEventListener(‘click’, function() { // Calculate actual score const total = state.questions.length; const attempted = state.userAnswers.filter(answer => answer !== null).length; const correct = state.userAnswers.filter((answer, index) => answer === state.questions[index].answer ).length; const percentage = total > 0 ? Math.round((correct / total) * 100) : 0; // Get student name const studentName = document.getElementById(‘user-name’) ? document.getElementById(‘user-name’).value : ‘Anonymous’; console.log(‘🎯 Auto-capturing score:’, {studentName, correct, total, percentage}); // Store results in localStorage const quizResult = { studentName: studentName, score: `${correct}/${total}`, percentage: percentage, timestamp: new Date().toISOString(), date: new Date().toLocaleString(), attempted: attempted, total: total, correct: correct }; // Save with unique key const resultKey = `physics_quiz_result_${Date.now()}`; localStorage.setItem(resultKey, JSON.stringify(quizResult)); console.log(‘💾 Saved to localStorage with key:’, resultKey); // Also store in a list of recent results const recentResults = JSON.parse(localStorage.getItem(‘physics_recent_quiz_results’) || ‘[]’); recentResults.push({ key: resultKey, timestamp: quizResult.timestamp, score: quizResult.score, studentName: studentName }); localStorage.setItem(‘physics_recent_quiz_results’, JSON.stringify(recentResults.slice(-20))); console.log(‘📋 Recent results updated:’, recentResults); // Show the normal results modal showResults(); // Show auto-capture confirmation setTimeout(() => { // Remove any existing score display const existingDisplay = document.querySelector(‘.auto-score-display’); if (existingDisplay) { existingDisplay.remove(); } // Create new score display const scoreDisplay = document.createElement(‘div’); scoreDisplay.className = ‘auto-score-display’; scoreDisplay.innerHTML = `

🎯 Auto-Captured Score

${correct}/${total}
${percentage}% – ${getGrade(percentage)}
✅ Automatically Saved
Go to Teacher Dashboard to submit this verified score
`; // Insert after the quiz container const quizContainer = document.getElementById(‘quiz-container’); if (quizContainer) { quizContainer.appendChild(scoreDisplay); } }, 1000); }); // Grade calculation function function getGrade(percentage) { if (percentage >= 90) return ‘A+’; if (percentage >= 80) return ‘A’; if (percentage >= 70) return ‘B’; if (percentage >= 60) return ‘C’; if (percentage >= 50) return ‘D’; return ‘F’; } // Test function to check if auto-capture is working function testAutoCapture() { console.log(‘🧪 Testing auto-capture system…’); const recentResults = JSON.parse(localStorage.getItem(‘physics_recent_quiz_results’) || ‘[]’); console.log(‘📊 Recent results found:’, recentResults); if (recentResults.length > 0) { console.log(‘✅ Auto-capture is WORKING! Found results:’, recentResults); alert(`✅ Auto-capture WORKING!\nFound ${recentResults.length} result(s)\nLatest: ${recentResults[0].score}`); } else { console.log(‘❌ No results found. Take quiz and click “Show Results” first.’); alert(‘❌ No auto-captured scores found.\nTake the quiz and click “Show Results” first.’); } } // Add test button to quiz page document.addEventListener(‘DOMContentLoaded’, function() { // Add test button after quiz loads setTimeout(() => { const testBtn = document.createElement(‘button’); testBtn.innerHTML = ‘🧪 Test Auto-Capture’; testBtn.style = ` position: fixed; bottom: 20px; right: 20px; background: #17a2b8; color: white; border: none; padding: 10px 15px; border-radius: 5px; cursor: pointer; z-index: 1000; font-size: 12px; `; testBtn.onclick = testAutoCapture; document.body.appendChild(testBtn); }, 2000); }); console.log(‘🚀 Auto-capture system loaded!’); // ==================== END AUTO-CAPTURE ====================