text: const question = document.querySelector("#question");
  const choices = Array.from(document.querySelectorAll(".choice-text"));
  const progressText = document.querySelector("#progressText");
  const scoreText = document.querySelector("#score");
  const progressBarFull = document.querySelector("#progressBarFull");
  
  let currentQuestion = {};
  let acceptingAnswers = true;
  let score = 0;
  let questionCounter = 0;
  let availableQuestions = [];
  
  let questions = [
    {
      question: "Which answer is a correct way of defining a variable?",
      choice1: "A. Javascript",
      choice2: "B. B = bob",
      choice3: "C. Document Object Model",
      choice4: "None of the above",
      answer: 2,
    },
    {
      question: "How do you add an Event Listener?",
      choice1: "A. input.addEventListener('click', function)",
      choice2: "B. Beat up scooter!",
      choice3: "C. Both are correct",
      choice4: "None of the above",
      answer: 1,
    },
    {
      question: "Who invented JavaScript?",
      choice1: "A. A Cookie Company",
      choice2: "B. Brendan Eich",
      choice3: "C. Dr Einstein",
      choice4: "None of the above",
      answer: 2,
    },
    {
      question: "Which is a querySelector Method?",
      choice1: "A. Language.querySelector()",
      choice2: "B. Hello World",
      choice3: "C. Document.querySelector()",
      choice4: "None of the above",
      answer: 3,
    },
  ];
  
  const SCORE_POINTS = 100;
  const MAX_QUESTIONS = 4;
  
  startGame = () => {
    questionCounter = 0;
    score = 0;
    availableQuestions = [...questions];
    getNewQuestion();
  };
  
  getNewQuestion = () => {
    if (availableQuestions.length === 0 || questionCounter > MAX_QUESTIONS) {
      localStorage.setItem("mostRecentScore", score);
  
      return window.location.assign("end.html");
    }
  
    questionCounter++;
    progressText.innerText = `Question ${questionCounter} of ${MAX_QUESTIONS}`;
    progressBarFull.style.width = `${(questionCounter / MAX_QUESTIONS) * 100}%`;
  
    const questionsIndex = Math.floor(Math.random() * availableQuestions.length);
    currentQuestion = availableQuestions[questionsIndex];
    question.innerText = currentQuestion.question;
  
    choices.forEach((choice) => {
      const number = choice.dataset["number"];
      choice.innerText = currentQuestion["choice" + number];
    });
  
    availableQuestions.splice(questionsIndex, 1);
  
    acceptingAnswers = true;
  };
  
  choices.forEach((choice) => {
    choice.addEventListener("click", (e) => {
      if (!acceptingAnswers) return;
  
      acceptingAnswers = false;
      const selectedChoice = e.target;
      const selectedAnswer = selectedChoice.dataset["number"];
  
      let classToApply =
        selectedAnswer == currentQuestion.answer ? "correct" : "incorrect";
  
      if (classToApply === "correct") {
        incrementScore(SCORE_POINTS);
      }
  
      selectedChoice.parentElement.classList.add(classToApply);
  
      setTimeout(() => {
        selectedChoice.parentElement.classList.remove(classToApply);
        getNewQuestion();
      }, 1000);
    });
  });
  
  incrementScore = (num) => {
    score += num;
    scoreText.innerText = score;
  };
  
  startGame();
  