Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

Hi, my code is working but it is not passing the test 11 and 12, can you please help me thank you!

Your code so far

const questions = [
  {
    category: "History",
    question: "What was the first successful English settlement in North America?",
    choices: ["Plymouth", "Jamestown", "Salem"],
    answer: "Jamestown"
  },
  {
    category: "Science",
    question: "What is the largest planet in our solar system?",
    choices: ["Earth", "Saturn", "Jupiter"],
    answer: "Jupiter"
  },
  {
    category: "Literature",
    question: "Who wrote the famous novel 'To Kill a Mockingbird'?",
    choices: ["F. Scott Fitzgerald", "Harper Lee", "Jane Austen"],
    answer: "Harper Lee"
  },
  {
    category: "Music",
    question: "Which British rock band, formed in 1960, is known for hits like 'I Want to Hold Your Hand' and 'Yesterday'?",
    choices: ["The Rolling Stones", "The Who", "The Beatles"],
    answer: "The Beatles"
  },
  {
    category: "Geography",
    question: "What is the world's largest desert?",
    choices: ["The Sahara", "The Gobi", "The Mojave"],
    answer: "The Sahara"
  },
];

const getRandomQuestion = () => {
  const random = Math.floor(Math.random() * questions.length);
  return questions[random];
}

const randomQuestion = getRandomQuestion();

const getRandomComputerChoice = (choice) => {
  const random = Math.floor(Math.random() * choice.length);
  return choice[random];
}

const computerChoice = getRandomComputerChoice(randomQuestion.choices);

const getResults = () => {
  const correctAnswer = randomQuestion.answer;
  return computerChoice == correctAnswer ? `The computer's choice is correct!` : `The computer's choice is wrong. The correct answer is: ${correctAnswer}`;
}

console.log(`Question: ${randomQuestion.question}`)
console.log(`Computer Choice: ${computerChoice}`);
console.log(getResults());

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36

Challenge Information:

Build a Quiz Game - Build a Quiz Game
https://www.freecodecamp.org/learn/full-stack-developer/lab-quiz-game/lab-quiz-game

Take another look at the requirements for the getResults function, it should have two parameters.

1 Like

Thanks! I overlook about that!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.