Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

Help my code seems to function properly but still fails test 11, 12, and 13

Your code so far

const questions = [
  {
  category: 'Michigan Facts 1',
  question: 'What is the state bird?',
  choices: ['Robin', 'Cardinal', 'Barn Owl'],
  answer: 'Robin'
},
{
  category: 'Michigan Facts 2',
  question: 'What is the state capitol?',
  choices: ['Detroit', 'Lansing', 'Grand Rapids'],
  answer: 'Lansing',
},
{
  category: 'Michigan Facts 3',
  question: 'What is the state flower?',
  choices: ['Tulip', 'Apple Blossom', 'Rose'],
  answer: 'Apple Blossom',
},
{
  category: 'Michigan Facts 4',
  question: 'What is the state tree?',
  choices: ['White Pine', 'Birch', 'Oak'],
  answer: 'White Pine'
},
{
  category: 'Michigan Facts 5',
  question: 'What is the state fish?',
  choices: ['Cat Fish', 'Perch', 'Brook Trout'],
  answer: 'Brook Trout'
}
];
function getRandomQuestion(questions) {
  const randomNumber = Math.floor(Math.random() * questions.length);
  return questions[randomNumber];
};

const randomQuestion = getRandomQuestion(questions);
const choices = randomQuestion.choices;


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

const randomComputerChoice = String(getRandomComputerChoice(randomQuestion.choices));

const correctAnswer = String(randomQuestion.answer);

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

Your browser information:

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

Challenge Information:

Build a Quiz Game - Build a Quiz Game

Could you say how did you determine everything works as intended?

by calling the function getResults
every time I input console.log(getResults(correctAnswer, randomComputerChoice));
result is a random question , random answer and what I believe to be the correct response to correct or incorrect random answer

Are you calling it with the correct arguments?

1 Like

You should have a function named getResults that takes the question object as the first parameter and the computer’s choice as the second parameter.

Is it taking the question object as argument?

1 Like

Thanks for the help I was struggling with that for too long.