Comprehensive Motion MCQ Challenge Class 9 Ch 7 Quiz
Comprehensive Test Quiz
`;
}function showLottieOverlay() {
lottieOverlay.innerHTML = ``;
lottieOverlay.style.display = 'flex';
setTimeout(() => {
lottieOverlay.style.display = 'none';
lottieOverlay.innerHTML = '';
}, 1500);
}function playCtqSound(type) {
try {
const ctx = new (window.AudioContext || window.webkitAudioContext)();
const o = ctx.createOscillator();
const g = ctx.createGain();
o.connect(g); g.connect(ctx.destination);
if (type === 'correct') {
o.type = 'triangle';
o.frequency.value = 660;
g.gain.value = 0.08;
} else {
o.type = 'square';
o.frequency.value = 220;
g.gain.value = 0.10;
}
o.start();
o.stop(ctx.currentTime + 0.18);
o.onended = () => ctx.close();
} catch (e) {}
}function showCtqConfetti() {
const colors = ['#f39c12', '#e74c3c', '#3498db', '#27ae60', '#9b59b6'];
confettiOverlay.innerHTML = '';
confettiOverlay.style.display = 'block';
for (let i = 0; i < 30; i++) {
const confetti = document.createElement('div');
confetti.className = 'ctq-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';
confettiOverlay.appendChild(confetti);
}
setTimeout(() => {
confettiOverlay.style.display = 'none';
confettiOverlay.innerHTML = '';
}, 2500);
}function attachEventListeners() {
document.querySelectorAll('.ctq-option').forEach(button => {
button.addEventListener('click', handleOptionClick);
});
const nextBtn = document.getElementById('ctq-next-btn');
if (nextBtn) nextBtn.addEventListener('click', handleNextQuestion);
const viewReportBtn = document.getElementById('ctq-view-report-btn');
if (viewReportBtn) viewReportBtn.addEventListener('click', handleViewReport);
const restartBtn = document.getElementById('ctq-restart-btn');
if (restartBtn) restartBtn.addEventListener('click', handleRestartQuiz);
}function handleOptionClick(event) {
if (isAnswerChecked) return;
const optionIndex = parseInt(event.target.dataset.option);
selectedOptionIndex = optionIndex;
isAnswerChecked = true;
const isCorrect = optionIndex === questions[currentQuestionIndex].correctAnswerIndex;
userAnswers.push({
questionIndex: currentQuestionIndex,
selectedOptionIndex: optionIndex,
isCorrect: isCorrect,
});
if (isCorrect) {
showCtqConfetti();
playCtqSound('correct');
} else {
showLottieOverlay();
playCtqSound('wrong');
}
render();
}function handleNextQuestion() {
selectedOptionIndex = null;
isAnswerChecked = false;
if (currentQuestionIndex < questions.length - 1) {
currentQuestionIndex++;
} else {
quizCompleted = true;
}
render();
}function handleViewReport() {
showReport = true;
render();
}function handleRestartQuiz() {
currentQuestionIndex = 0;
selectedOptionIndex = null;
isAnswerChecked = false;
userAnswers = [];
quizCompleted = false;
showReport = false;
render();
}document.addEventListener('DOMContentLoaded', render);
})();
Please Ask any Study related help from the below form!
If you want to get the free service of getting posts directly in your mail, you can sign up for our free newsletter.
Leave a Comment