Motion MCQ Challenge Class 9 Ch 7 Quiz| Test Yourself!

Acceleration

Acceleration Quiz
`; } createConfetti() { const colors = ['#f39c12', '#e74c3c', '#3498db', '#27ae60', '#9b59b6']; const confettiContainer = document.createElement('div'); confettiContainer.className = 'confetti-container'; for (let i = 0; i < 30; i++) { const confetti = document.createElement('div'); confetti.className = 'confetti'; confetti.style.left = Math.random() * 100 + '%'; confetti.style.background = colors[Math.floor(Math.random() * colors.length)]; confetti.style.animationDelay = Math.random() * 0.5 + 's'; confetti.style.animationDuration = (Math.random() * 0.5 + 1.5) + 's'; confettiContainer.appendChild(confetti); } document.body.appendChild(confettiContainer); setTimeout(() => { document.body.removeChild(confettiContainer); }, 2500); } attachEventListeners() { document.querySelectorAll('.option').forEach(button => { button.addEventListener('click', (e) => this.handleOptionClick(e)); }); const nextBtn = document.getElementById('next-btn'); if (nextBtn) nextBtn.addEventListener('click', () => this.handleNextQuestion()); const viewReportBtn = document.getElementById('view-report-btn'); if (viewReportBtn) viewReportBtn.addEventListener('click', () => this.handleViewReport()); const restartBtn = document.getElementById('restart-btn'); if (restartBtn) restartBtn.addEventListener('click', () => this.handleRestartQuiz()); } handleOptionClick(event) { if (this.isAnswerChecked) return; const optionIndex = parseInt(event.target.dataset.option); this.selectedOptionIndex = optionIndex; this.isAnswerChecked = true; const isCorrect = optionIndex === this.questions[this.currentQuestionIndex].correctAnswerIndex; this.userAnswers.push({ questionIndex: this.currentQuestionIndex, selectedOptionIndex: optionIndex, isCorrect: isCorrect, }); if (isCorrect) { this.createConfetti(); } this.render(); } handleNextQuestion() { this.selectedOptionIndex = null; this.isAnswerChecked = false; if (this.currentQuestionIndex < this.questions.length - 1) { this.currentQuestionIndex++; } else { this.quizCompleted = true; } this.render(); } handleViewReport() { this.showReport = true; this.render(); } handleRestartQuiz() { this.currentQuestionIndex = 0; this.selectedOptionIndex = null; this.isAnswerChecked = false; this.userAnswers = []; this.quizCompleted = false; this.showReport = false; this.render(); } } document.addEventListener('DOMContentLoaded', () => { new Quiz(); });

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top