Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

Hi all,
I need help with my getResults function. My code passes all test cases but number 11. The test case is asking for two parameters “the question object as the first parameter and the computer’s choice as the second parameter.” I cannot see how my getResults function fails this test case. Any help is appreciated!

Your code so far

const question1 = {
    category: "1",
    question: "Who?",
    choices: ["Bob", "Fred", "Tim"],
    answer:"Bob"
}

const question2 = {
    category: "2",
    question: "What?",
    choices: ["Person", "Object", "Concept"],
    answer:"Concept"
}

const question3 = {
    category: "W",
    question: "Where?",
    choices: ["Up", "Down", "Left"],
    answer:"Down"
}

const question4 = {
    category: "W",
    question: "Why?",
    choices: ["Yes", "No", "Maybe"],
    answer:"Yes"
}

const question5 = {
    category: "H",
    question: "How?",
    choices: ["Plan A", "Plan B", "Plan C"],
    answer:"Plan B"
}

const questions = [question1, question2, question3, question4, question5]

const getRandomQuestion = (questions) => {
  const randNum = Math.floor(Math.random() * questions.length)

  return questions[randNum]
}

const getRandomComputerChoice = (choices) => {
  const randNum = Math.floor(Math.random() * 3)

  return choices[randNum]
}

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



Your browser information:

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

Challenge Information:

Build a Quiz Game - Build a Quiz Game

Hi there

The stories ask you create an array of objects to hold the questions. That should then be passed to the getResults function.

I suspect this line is causing the tests to fail. Is there a better way to check if the question answer is the same as the computer’s choice?

This was it. Swapped to a “==” method. This was annoying because for all I could see my code passed each example given

Yes. I understand. But the tests are probably set up to test for equality.

What is the correct answer is “Hamburger” but the computer choice is “Ham”?

I guess there is a similar situation in the data used for testing, but I think it was accidental

Yes. I tried to think of an example like that when I replied, but nothing came to mind. :slight_smile: Thanks for doing that!