create 100 quiz questions on taylor swift in javascript

To create 100 quiz questions on Taylor Swift in JavaScript, we can start by creating an array of objects, where each object contains the question, the possible answers, and the correct answer.

Here is an example of how we can create the quiz questions:

index.tsx
const quizQuestions = [
  {
    question: "What's the name of Taylor Swift's first album?",
    options: ["1989", "Red", "Speak Now", "Taylor Swift"],
    answer: "Taylor Swift"
  },
  {
    question: "Which song did Taylor Swift win her first Grammy for?",
    options: ["Shake It Off", "You Belong With Me", "Fearless", "Mean"],
    answer: "White Horse"
  },
  // Add 98 more questions here ...
];
401 chars
14 lines

We can create a function that renders the quiz questions and allows the user to select an answer. The function will then check if the selected answer is correct and update the score accordingly.

index.tsx
function renderQuestion(question) {
  const container = document.getElementById("quiz-container");
  const questionEl = document.createElement("h2");
  questionEl.textContent = question.question;
  container.appendChild(questionEl);

  const options = question.options;
  for (let i = 0; i < options.length; i++) {
    const optionEl = document.createElement("button");
    optionEl.textContent = options[i];
    optionEl.onclick = function () {
      if (optionEl.textContent === question.answer) {
        alert("Correct!");
        // Increase the score by 1
      } else {
        alert("Incorrect!");
      }
      // Move to the next question
    };
    container.appendChild(optionEl);
  }
}

// Render the first question
renderQuestion(quizQuestions[0]);
763 chars
26 lines

We can also add a timer to the quiz and limit the amount of time the user has to answer each question.

index.tsx
let timeLeft = 60;

function countdown() {
  const timerEl = document.getElementById("timer");
  timerEl.textContent = `Time left: ${timeLeft}`;
  timeLeft--;
  if (timeLeft < 0) {
    alert("Time's up!");
    // Move to the next question
  } else {
    setTimeout(countdown, 1000);
  }
}

// Start the countdown
countdown();
326 chars
17 lines

With some additional styling and functionality, we can create a complete quiz app with 100 questions on Taylor Swift using JavaScript.

gistlibby LogSnag