Algebra Practice Quiz
${q.question}
`;
}
function getSelected() {
const answers = document.querySelectorAll('input[name="answer"]');
let answer;
answers.forEach(ans => { if(ans.checked) answer = ans.value; });
return answer;
}
submitBtn.addEventListener('click', () => {
const answer = getSelected();
if(!answer) {
alert("Please select an answer!");
return;
}
if(answer === quizData[currentQuiz].correct) score++;
currentQuiz++;
if(currentQuiz < quizData.length) loadQuiz();
else {
quiz.innerHTML = '';
submitBtn.style.display = 'none';
result.innerText = `You scored ${score} out of ${quizData.length}!`;
}
});
loadQuiz();