`;
quizContainer.appendChild(questionDiv);
});
}
function selectOption(event) {
if (event.target.classList.contains('option')) {
const questionIndex = event.target.getAttribute('data-question');
const optionButtons = document.querySelectorAll(`.option[data-question="${questionIndex}"]`);
optionButtons.forEach(button => button.classList.remove('selected'));
event.target.classList.add('selected');
}
}
function calculateScore() {
let score = 0;
quizData.forEach((questionData, index) => {
const selectedOption = document.querySelector(`.option.selected[data-question="${index}"]`);
if (selectedOption && parseInt(selectedOption.getAttribute('data-option')) === questionData.correct) {
score++;
}
});
return score;
}
function showResult() {
const score = calculateScore();
resultContainer.textContent = `You scored ${score} out of ${quizData.length}!`;
let feedback = "";
if (score === quizData.length) {
feedback = "Perfect! You're a pet bonding expert!";
} else if (score >= quizData.length * 0.8) {
feedback = "Great job! You have a strong understanding of pet bonding.";
} else if (score >= quizData.length * 0.6) {
feedback = "Good effort! There's still room to learn more about bonding with your pet.";
} else {
feedback = "Keep learning! Building a strong bond with your pet is a journey.";
}
resultContainer.innerHTML += `