Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

I’m missing something here that I can’t wrap my head around. I cannot seem to pass 11-13. I think I am misunderstanding how the questions and answers are supposed to come together for the getResults function.

Your code so far

const questions = [
  {
    category: "Animal",
    question: "What is the best animal?",
    choices: ['Dog', 'Cat', 'Fish'],
    answer: 'Dog'
  },
  {
    category: "Drink",
    question: "What is the best drink?",
    choices: ['Soda', 'Water', 'Tea'],
    answer: 'Water'
  },
  {
    category: "Food",
    question: 'What is the best food?',
    choices: ['Beef', 'Chicken', 'Ice Cream'],
    answer: 'Ice Cream'
  },
  {
    category: "Movie",
    question: 'What is the best movie?',
    choices: ['Princess Bride', 'Three Amigos', 'Ghostbusters'],
    answer: 'Princess Bride',
  },
  {
    category: "Music",
    question: 'What is the best music?',
    choices: ['Jazz', 'Classical', 'Pop'],
    answer: 'Classical'
  }
];

function getRandomQuestion(questions) {
  let randomQuestion = Math.floor(Math.random() * questions.length);
  return questions[randomQuestion];
}

function getRandomComputerChoice(choices) {
  let randomComputerChoice = Math.floor(Math.random() * choices.length);
  return choices[randomComputerChoice];
}

function getResults(questions, choices) {
  if (randomComputerChoice === answer)
  return "The computer's choice is correct!"
  else {
    return `The computer's choice is wrong. The correct answer is: ${answer}`
  }
}

Your browser information:

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

Challenge Information:

Build a Quiz Game - Build a Quiz Game

yes, you are

you should not refer to global variables inside the getResults function: the first argument is the question object (one of the objects from the array), the second argument is the computer choice (one of the strings inside the choices array)

you should checj uf the computer has the right answer using those

So, something like this? Or is that still using the wrong parameters?

function getResults(randomQuestion, randomComputerChoice) {
  if (randomComputerChoice === answer)
  return "The computer's choice is correct!"
  else {
    return `The computer's choice is wrong. The correct answer is: ${answer}`
  }
}

where are you getting answer from? it’s your current issue

Yeah, I thought that would be a problem. I’m not sure how to access the specific answer for the randomQuestion that is chosen. I’ll keep working on it. Thanks.

you know it’s one of the objects, they all have the same structure, look at how the answer is saved in the objects

I thought it would be something like this, but it is also not working. I’ll keep trying.

function getResults(randomQuestion, randomComputerChoice) {
  if (randomComputerChoice === answer)
  return "The computer's choice is correct!"
  else {
    return `The computer's choice is wrong. The correct answer is: ${randomQuestion.answer}`
  }
}

you have not changed here

I got it! This worked, but I’m not sure it was ultimately the correct solution. Thank you for all of your help!

does it passes the tests? it’s correct

Yep, thanks. I should probably delete the code I posted with the solution. Appreciate the help.