* Designed by ShrikantSir
🏆 VIBRANT CHAMPION!
You have conquered the Set 12 challenge!
let currentIndex = 0, timeLeft = 60, timerInterval;
const winSnd = new Audio('https://actions.google.com/sounds/v1/cartoon/clime.ogg');
const loseSnd = new Audio('https://actions.google.com/sounds/v1/foley/metal_clank.ogg');
function startTimer() {
clearInterval(timerInterval);
timeLeft = 60;
updateTimerUI();
timerInterval = setInterval(() => {
timeLeft--;
updateTimerUI();
if (timeLeft <= 0) triggerFail();
}, 1000);
}
function updateTimerUI() {
document.getElementById('math-timer').innerText = timeLeft;
document.getElementById('time-fill').style.width = (timeLeft / 60 * 100) + "%";
}
function loadQuestion() {
const data = quizData[currentIndex];
document.getElementById('streak-val').innerText = currentIndex;
document.getElementById('question-text').innerText = data.q;
const container = document.getElementById('options-container');
container.innerHTML = "";
const shuffledOptions = [...data.o].sort(() => Math.random() - 0.5);
shuffledOptions.forEach(opt => {
const btn = document.createElement('button');
btn.className = 'opt-btn';
btn.innerText = opt;
btn.onclick = () => checkMastery(btn, data.a);
container.appendChild(btn);
});
startTimer();
}
function checkMastery(clickedBtn, correctAnswer) {
clearInterval(timerInterval);
const allButtons = document.querySelectorAll('.opt-btn');
allButtons.forEach(b => b.style.pointerEvents = 'none');
if (clickedBtn.innerText === correctAnswer) {
clickedBtn.classList.add('correct-flash');
winSnd.play();
confetti({ particleCount: 100, spread: 70, origin: { y: 0.8 }, colors: ['#ff0099', '#ffff00'] });
setTimeout(() => {
currentIndex++;
if (currentIndex >= quizData.length) showWinScreen();
else loadQuestion();
}, 1000);
} else {
clickedBtn.classList.add('wrong-flash');
allButtons.forEach(b => { if (b.innerText === correctAnswer) b.classList.add('correct-flash'); });
loseSnd.play();
setTimeout(() => { triggerFail(); }, 2000);
}
}
function triggerFail() {
document.getElementById('quiz-master-box').classList.add('shake');
setTimeout(() => {
document.getElementById('quiz-master-box').classList.remove('shake');
currentIndex = 0;
loadQuestion();
}, 800);
}
function resetToStart() {
currentIndex = 0;
document.getElementById('game-area').style.display = 'block';
document.getElementById('win-screen').style.display = 'none';
loadQuestion();
}
function showWinScreen() {
document.getElementById('game-area').style.display = 'none';
document.getElementById('win-screen').style.display = 'block';
confetti({ particleCount: 500, spread: 150 });
}
loadQuestion();
Comments
Post a Comment