Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

JavaScript Lab: “Create A Quiz Game”

My code is not throwing any errors, and it appears to fulfill the lab requirements. Unfortunately, however, I am failing User Story #9, and I am having difficulty in finding the “why” of the matter.

User Story #9:

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. The function should return The computer’s choice is correct! if the answer is correct. Otherwise, it returns The computer’s choice is wrong. The correct answer is: , where is the value of the correct answer to the chosen question.

Any help would be greatly appreciated!

Your code so far

let questions = [
  {
    category: "Literature",
    question: "What is a famous series of books written by J.R.R. Tolkien?",
    choices: ["Labrynth", "Harry Potter", "The Lord of the Rings"],
    answer: "The Lord of the Rings"
  },
  {
    category: "Programming",
    question: "Which programming language shares characteristics of Monty Python?",
    choices: ["R", "Go", "Python"],
    answer: "Python"
  },
  {
    category: "Geography",
    question: "Which U.S. national park is home to a supervolcano?",
    choices: ["King\'s Canyon", "Yosemite", "Yellowstone"],
    answer: "Yellowstone"
  },
  {
    category: "Animals",
    question: "Which animal is known as \'Man\'s Best Friend?",
    choices: ["Penguin", "Cat", "Dog"],
    answer: "Dog"
  },
  {
    category: "Languages",
    question: "Which language is known for being a Romantic language?",
    choices: ["Klingon", "Japanese", "French"],
    answer: "French"
  }
]

function getRandomQuestion (questionBank) {
  return questionBank[Math.floor(Math.random() * questionBank.length)];
}

function getRandomComputerChoice(answerBank) {
  return answerBank[Math.floor(Math.random() * answerBank.length)];
}

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

let randomQuestion = getRandomQuestion(questions);
let computerChoice = getRandomComputerChoice(randomQuestion.choices);
getResults(randomQuestion, computerChoice);

Your browser information:

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

Challenge Information:

Build a Quiz Game - Build a Quiz Game

Hi @rkcole72984

User stories 11, 12, and 13 do not pass.

  1. If the computer choice matches the answer, getResults should return The computer's choice is correct!

You need to return something, not console log it.

Happy coding

Are you returning here?

Thanks to you and to @Teller!

If that was the only caveat (user error) on my first attempt at this, that’s not bad. Sorry for my oversight on that one!

I really appreciate the input.

1 Like