const quizData = [
    {
      question: "1. What is the minimum age you have to be to run for president?",
      options: [ "32 years", "35 years", "38 years", "42 years"],
      answer: "35 years"
    },
    {
      question: "2. What is the electoral college?",
      options: ["the electors for each state", "a monument", "a political party", "the electors for the whole country"],
      answer: "the electors for each state"
    },
    {
      question: "3. How many votes does one candidate need to win the elections and to become president?",
      options: ["250", "270", "320", "370"],
      answer: "270"
    },
    {
      question: "4. Does Kansas follow the principle of an open or a closed primary?",
      options: ["open", "closed", "neither", "both"],
      answer: "closed"
    },
    {
      question: "5. How many phases does the U.S. election go through?",
      options: ["1", "2", "3", "4"],
      answer: "4"
    },
    {
      question: "6. What is the minimum age required to vote in U.S. elections?",
      options: ["15", "17", "18", "21"],
      answer: "18"
    },
    {
      question: "7. How often is the president of the United States elected?",
      options: ["every 2 years", "every 3 years", "every 4 years", "every 5 years"],
      answer: "every 4 years"
    },
    {
      question: "8. Which of the following statements is an election target of Donald Trump?",
      options: ["minimizing violence in schools", "substituting the affordadble care act", "fighting against the climate change"],
      answer: "substituting the affordadble care act"
    },
    {
      question: "9. Which political party did Kansas principally vote for in the last elections?",
      options: ["for the Republicans", "for the Democrats", "for the Liberterians", "for the Greens"],
      answer: "for the Republicans"
    },
    {
      question: "10. Which of those two elections targets will make Kansas not to vote for Kamala Harris?",
      options: ["new immigration laws", "harder gun laws"],
      answer: "harder gun laws"
    },
    {
      question: "11. Which U.S. president won the presidential election in Kansas in 2020?",
      options: ["Joe Biden","Donald Trump", "Barack Obama", "George W. Bush"],
      answer: "Donald Trump"
    },
    {
      question: "12. In which year did the state of Kansas last elect a Democratic presidential candidate?",
      options: ["1964","1976", "1980", "1992"],
      answer: "1964"
    },
    {
      question: "13. What type of voting system is used in U.S. presidential elections?",
      options: ["Proportional representation", "First-past-the-post","Electoral College", "Ranked-choice voting"],
      answer: "Electoral College"
    },
    {
      question: "14. What is one goal of Kamala Harris in economy?",
      options: ["She‘s going to support price gouging", "She‘s going to ban price gouging",  "She‘s going to lower price gouging","She‘s going to do nothing for price gouging"],
      answer: "She‘s going to ban price gouging"
    },
    {
      question: "15. How many Americans will Kamala Harris be benefiting through tax cuts?",
      options: ["100.000 Americans", "200.000 Americans", "300.000 Americans", "400.000 Americans"],
      answer: "100.000 Americans"
    },
    {
      question: "16. In the metaphor of our game simulation, the plane stands for the community of: (video with plane)",
      options: ["the democratic party", "people-of-color in the U.S.", "all U.S.-citizens", "female citizens of the U.S."],
      answer: "all U.S.-citizens"
    },
    {
      question: "17. Which religion is the most common in Kansas?",
      options: ["Islam", "Hinduism", "Buddhism","Christianity"],
      answer: "Christanity"
    },
    {
      question: "18. What is Kansas principally known for?",
      options: ["it's beaches", "it's agriculture", "it's wild animals","it's big cities"],
      answer: "it's agriculture"
    },
    {
      question: "19. What is Kansas' state animal?",
      options: ["an eagle", "a horse", "a tiger", "a buffalo"],
      answer: "a buffalo"
    },
  ];
  
  const questionElement = document.getElementById("question");
  const optionsElement = document.getElementById("options");
  
  let currentQuestion = 0;
  let score = 0;
  
  function showQuestion() {
    const question = quizData[currentQuestion];
    questionElement.innerText = question.question;
  
    optionsElement.innerHTML = "";
    question.options.forEach(option => {
      const button = document.createElement("button");
      button.innerText = option;
      optionsElement.appendChild(button);
      button.addEventListener("click", selectAnswer);
    });
  }
  
  function selectAnswer(e) {
    const selectedButton = e.target;
    const answer = quizData[currentQuestion].answer;
  
    if (selectedButton.innerText === answer) {
      score++;
    }
  
    currentQuestion++;
  
    if (currentQuestion < quizData.length) {
      showQuestion();
    } else {
      showResult();
    }
  }
  
  function showResult() {
    quiz.innerHTML = `
    <h1>Quiz Completed!</h1>
      <p>Your score: ${score}/${quizData.length}</p>
      <p>If you want to test your knowledge again, please reload this website!</p>
    `;
  }
  
  showQuestion();