Build a Quiz Game - User stories 11, 12, and 13 don't pass but code works

Tell us what’s happening:

Javascript: Build a Quiz Game - Conditions / user stories 11, 12, and 13 are not being met even though as far as I am concerned my code does in fact pass these conditions. I can’t understand why it doesn’t work because my code seems to run correctly and does everything described in the brief. Any help would be appreciated, thanks.

Your code so far

const questions = [];

const question1 = {
  category : "Music",
  question : "What model of Fender guitar did Jimi Hendrix play?",
  choices : ["Telecaster", "Stratocaster", "Les Paul"],
  answer : "Stratocaster",
}

const question2 = {
  category : "Sport",
  question : "Which driver is currently winning the 2025 Formula 1 season?",
  choices : ["Max Verstappen", "Charles Leclerc", "Oscar Piastri"],
  answer : "Oscar Piastri",
}

const question3 = {
  category : "TV",
  question : "Which Game Of Thrones character killed The Night King?",
  choices : ["Arya Stark", "Jon Snow", "Jaime Lannister"],
  answer : "Arya Stark",
}

const question4 = {
  category : "Food",
  question : "Which food originated from Italy?",
  choices : ["Curry", "Pasta", "Burritos"],
  answer : "Pasta",
}

const question5 = {
  category : "Science",
  question : "Which element has the symbol \"Au\" on the periodic table?",
  choices : ["Mercury", "Silver", "Gold"],
  answer : "Gold",
}

questions.push(question1, question2, question3, question4, question5);

const selectedQuestion = getRandomQuestion(questions);

console.log(selectedQuestion.question);

const computerAnswer = getRandomComputerChoice(selectedQuestion.choices);

console.log(`The computer's answer is: ${computerAnswer}`);

getResults(selectedQuestion, computerAnswer);

function getRandomQuestion (questions) {
return questions[Math.round(Math.random() * 4)];
}

function getRandomComputerChoice (choices) {
return choices[Math.round(Math.random() * 3)];
}

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

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

Challenge Information:

Build a Quiz Game - Build a Quiz Game

This is the important part of the hints:

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

 The function should return

It needs to return something, not send it to the console.

Also, you are hard-coding here and using the wrong Math method.

Thanks for the help, that’s solved it I’ve been scratching my head for the last couple of days with that one. It seems so obvious in hindsight!

My hindsight is also much better than my foresight