Build a Quiz Game - Code works but won't pass user story 9

Tell us what’s happening:

My code seems to work just fine, but it won’t pass user story 9. “You should have a function named getRandomComputerChoice that takes the array of the available choices as a parameter, and returns a random answer to the selected question.”

Another problem i notice is that even when the computer choice is correct, the function only returns the “the computer choice is wrong” result. Yet it did pass that user story.

Can someone please explain me what i did wrong?

Thank you in advance.

Your code so far

const questions = [
  {
    category: "Anatomy",
    question: "which muscle causes dorsiflexion in the ankle?",
    choices: ["m. tibialis posterior", "m. tibialis anterior", "m. peroneus brevis"],
    answer: "m. tibialis anterior",
  },
  {
    category: "Pathology",
    question: "which pathology is characterized by starting pain when getting out of bed in the morning?",
    choices: ["Mortons neuroma", "Unguis incarnatus", "Plantar fasciitis"],
    answer: "Plantar fasciitis",
  },
  {
    category: "Orthopedics",
    question: "What is the normal range of motion of ankle dorsiflexion?",
    choices: ["15 degrees", "30 degrees", "10 degrees"],
    answer: "15 degrees",
  },
  {
    category: "Neurology",
    question: "Which nerve is involved in tarsal tunnel syndrome?",
    choices: ["Superficial peroneal nerve", "Saphenous nerve nerve", "Posterior tibial nerve"],
    answer: "Posterior tibial nerve",
  },
  {
    category: "Podiatry",
    question: "Which treatment option is NOT part of the Podiatrist treatment possibilities?",
    choices: ["Footwear advice","Shockwave therapy", "Custom made inlsoles"],
    answer: "Shockwave therapy",
  },
];

function getRandomQuestion(questions) {
  const randomIndex = Math.floor(Math.random() * questions.length);
  const randomQuestionObject = questions[randomIndex];
  return randomQuestionObject;

}
const randomQuestionObject = getRandomQuestion(questions);

console.log("Category:", randomQuestionObject['category']);
console.log("\n" + "Question:", randomQuestionObject['question']);
console.log("\n" + "Choices:", randomQuestionObject['choices'].join(", "));


function getRandomComputerChoice(randomQuestionObject) {
  const randomIndex = Math.floor(Math.random() * randomQuestionObject['choices'].length);
  const computerAnswer = randomQuestionObject['choices'][randomIndex];
  return computerAnswer
}

const randomComputerChoice = getRandomComputerChoice(randomQuestionObject);

console.log("\n" + "Computer answer:", randomComputerChoice);

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

console.log("\n" + getResults(randomQuestionObject));














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

You should have a function named getRandomComputerChoice that takes the array of the available choices as a parameter

Does your code align with this user story?

Are you calling getResults() with all the required parameters?

are you implementing this correctly?