Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

I’m not passing tests 11, 13, and 14, but passing 12 so I’m very confused. How is it not two parameters, one for an object and the other for the choice?

Your code so far

const questions = [
  {
    category: "personal",
    question: "What's the phobia of clowns called?",
    choices: ["Coulrophobia", "Aracnophobia", "Agoraphobia"],
    answer: "Coulrophobia",
  },
  {
    category: "personal",
    question: "What is the name of my favorite book?",
    choices: ["The Road", "IT", "Blood Meridian"],
    answer: "The Road",
  },
  {
    category: "trivia",
    question: "What is the name of the famous ship that crashed into an iceberg?",
    choices: ["Titanic", "USS Philidelphia", "The Montauk"],
    answer: "Titanic",
  },
  {
    category: "trivia",
    question: "Where was Mothman sighted?",
    choices: ["Point Pleasant", "Philidelphia", "Chicago"],
    answer: "Point Pleasant",
  },
  {
    category: "other",
    question: "What is the meaning of life, the universe, and everything?",
    choices: ["47", "56", "42"],
    answer: "42",
  }
];

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

const randomQ = getRandomQuestion(questions)

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

const comAnswer = getRandomComputerChoice(randomQ.choices);

//*Good to this point*//

function getResults(object, choice){
  let answer = object.answer;
  let comChoice = choice
  if (comChoice === answer){
    return "The computer's choice is correct!"
  }
  else if (comChoice !== answer){
    return `The computer's choice is wrong. The correct answer is ${answer}`;
  }
}

console.log();

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Quiz Game - Build a Quiz Game

Why are you doing this? The parameter already has the value for the computer’s choice.

And why are you adding another if? If if (comChoice === answer) is false, doesn’t it follow then that comChoice !== answer is true?

Make sure the message you return when the computer’s choice is wrong matches exactly to the text in the instructions. (You are missing something.)

LOL in all honesty that was part of me just trying different things to see if it would fix it. Thank you so much for your help! Your second suggestion helped me clean up my code and it turns out you were 100% correct and I was just missing a single punctuation from the quote :face_with_peeking_eye: I feel silly but thank you!

No need to feel silly. We’re all learning here. And attention to those small details is one of the things that makes programming so challenging.

1 Like