Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

Ok. My code works in the console but i simply can’t get it to pass the tests from 11 and forward.

I believe I take the question as an object and the computer choice as a string in the getResults function.

Even though I can see that a lot of people have similar issues on this forum, I can’t use their posts as a solution on my problem.

Your code so far

const questions = [
    {
    category: "Hard Questions",
    question: "What's the definition of the word codswallop?",
    choices: ["Gibberish", "Nonsense", "Philosophy"],
    answer: "Nonsense"
    },
    {
    category: "Easy Questions",
    question: "Which French emperor was attacked by a horde of rabbits?",
    choices: ["Trump", "Bono", "Napoleon Bonaparte"],
    answer: "Napoleon Bonaparte"
    },
    {
    category: "Hard Questions",
    question: "What Australian animal poops in cubes?",
    choices: ["The Wombat", "Human Being", "Android"],
    answer: "The Wombat"
    },
    {
    category: "Hard Questions",
    question: "After urinating on a bomb during WWII, Juliana, a Great Dane, was awarded what honor?",
    choices: ["Nobel Peace Prize", "An Oscar", "The Blue Cross Medal"],
    answer: "The Blue Cross Medal"
    },
    {
    category: "Medium Questions",
    question: "What is Bob Dylan's real last name?",
    choices: ["Trump", "Zimmerman", "Bono"],
    answer: "Zimmerman"
    }
  ]

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

const getRandomComputerChoice = (choices) => {
  let randomNum = Math.floor(Math.random() * choices.length);
  let randomChoice = choices[randomNum];
  return randomChoice;
}

let quizResult = getRandomQuestion(questions);
let computerChoice = quizResult.choices;
let finalComputerChoice = getRandomComputerChoice(computerChoice);
let rightAnswer = quizResult.answer;

const getResults = (question, comAnswer) => {
  if (question.answer === comAnswer) {
    return "The computer's choice is correct"
  } else return "The computer's choice is wrong. The correct answer is '" + quizResult.answer + "'";
}

console.log(quizResult.question + "\n");
console.log(`Computer answer: ${finalComputerChoice} \n`);
console.log(getResults(quizResult, finalComputerChoice));
console.log("\n")
console.log(`The type of quizResult is: ${typeof(quizResult)}`)
console.log(`The type of rightAnswer is: ${typeof(rightAnswer)}`)
console.log(`The type of computerChoice is: ${typeof(computerChoice)}`)
  

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36

Challenge Information:

Build a Quiz Game - Build a Quiz Game

There are some differences in punctuation in your final output strings.

Do not use global variables in your function, make sure you are using the parameters.

you never create quizAnswer inside the function, where does this come from?

Welcome to the forum @holmgreen !

The message returned by getResults should match the text in the instructions exactly. Fix that and your code should pass.

Good job!

EDIT: Oops…I see that global variable now in your getResults function that @pkdvalis mentioned.

Oh yes!!! It was my lame nemesis: punctuation and the global variable inside the function. Thanks a lot!!!

A bit strange though, that it fails on test 11 that tells me to pass an object and a string. Anyway. I’m on my way. Thanks again.

1 Like

The tests are simple tests, and cannot account for every variation they encounter. Do not try to code based only on the tests.

If a test is failing you need to check that the User Stories are implemented correctly.

Yes. got it. Thanks a lot.

In that way, these tests are extremely educational, because I can figure out a solution that actually works, but need to rethink it according to the tests.