Changed around line 1
+ const topics = document.querySelectorAll('[data-topic]');
+ const quizSection = document.getElementById('quiz-section');
+ const questionContainer = document.getElementById('question-container');
+ const submitAnswerBtn = document.getElementById('submit-answer');
+ const nextQuestionBtn = document.getElementById('next-question');
+ const scoreboard = document.getElementById('scoreboard');
+ const correctAnswersSpan = document.getElementById('correct-answers');
+ const incorrectAnswersSpan = document.getElementById('incorrect-answers');
+
+ let currentTopic = '';
+ let currentQuestionIndex = 0;
+ let correctAnswers = 0;
+ let incorrectAnswers = 0;
+
+ const questions = {
+ history: [
+ {
+ question: "Who was the first president of the United States?",
+ options: ["George Washington", "Thomas Jefferson", "Abraham Lincoln", "John Adams"],
+ answer: "George Washington"
+ },
+ {
+ question: "In which year did World War II end?",
+ options: ["1945", "1939", "1941", "1943"],
+ answer: "1945"
+ }
+ ],
+ science: [
+ {
+ question: "What is the chemical symbol for water?",
+ options: ["H2O", "CO2", "O2", "H2"],
+ answer: "H2O"
+ },
+ {
+ question: "Which planet is known as the Red Planet?",
+ options: ["Mars", "Venus", "Jupiter", "Saturn"],
+ answer: "Mars"
+ }
+ ],
+ math: [
+ {
+ question: "What is 2 + 2?",
+ options: ["4", "3", "5", "6"],
+ answer: "4"
+ },
+ {
+ question: "What is the square root of 64?",
+ options: ["8", "6", "10", "12"],
+ answer: "8"
+ }
+ ],
+ literature: [
+ {
+ question: "Who wrote 'Romeo and Juliet'?",
+ options: ["William Shakespeare", "Charles Dickens", "Jane Austen", "Mark Twain"],
+ answer: "William Shakespeare"
+ },
+ {
+ question: "What is the main character in 'Moby Dick'?",
+ options: ["Captain Ahab", "Ishmael", "Queequeg", "Starbuck"],
+ answer: "Captain Ahab"
+ }
+ ]
+ };
+
+ topics.forEach(topic => {
+ topic.addEventListener('click', () => {
+ currentTopic = topic.dataset.topic;
+ document.getElementById('topic-selection').classList.add('hidden');
+ quizSection.classList.remove('hidden');
+ loadQuestion();
+ });
+ });
+
+ function loadQuestion() {
+ const question = questions[currentTopic][currentQuestionIndex];
+ questionContainer.innerHTML = `
+
${question.question} + ${question.options.map(option => `
+
+
+ ${option}
+
+ `).join('')}
+ `;
+ submitAnswerBtn.classList.remove('hidden');
+ }
+
+ submitAnswerBtn.addEventListener('click', () => {
+ const selectedAnswer = document.querySelector('input[name="answer"]:checked');
+ if (selectedAnswer) {
+ const question = questions[currentTopic][currentQuestionIndex];
+ if (selectedAnswer.value === question.answer) {
+ correctAnswers++;
+ } else {
+ incorrectAnswers++;
+ }
+ updateScoreboard();
+ submitAnswerBtn.classList.add('hidden');
+ nextQuestionBtn.classList.remove('hidden');
+ }
+ });
+
+ nextQuestionBtn.addEventListener('click', () => {
+ currentQuestionIndex++;
+ if (currentQuestionIndex < questions[currentTopic].length) {
+ loadQuestion();
+ nextQuestionBtn.classList.add('hidden');
+ submitAnswerBtn.classList.remove('hidden');
+ } else {
+ quizSection.classList.add('hidden');
+ scoreboard.classList.remove('hidden');
+ }
+ });
+
+ function updateScoreboard() {
+ correctAnswersSpan.textContent = correctAnswers;
+ incorrectAnswersSpan.textContent = incorrectAnswers;
+ }