Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

Im able to get and display the choices arrays.
But still the test 8 are not able to pass the test

Your code so far

const questions = [{
  "category":"food",
  "question":"monkey favorite food?",
  "choices":["apple","banana","burito"],
  "answer":"banana"
},
{
  "category":"anime",
  "question":"best selling manga?",
  "choices":["OPM","OP","DB"],
  "answer":"OP"
},
{
  "category":"food",
  "question":"panda favorite food?",
  "choices":["apple","bamboo","charcoal"],
  "answer":"bamboo"
},
{
  "category":"color",
  "question":"what is the color of the grass?",
  "choices":["pink","blue","green"],
  "answer":"green"
},
{
  "category":"tech",
  "question":"who own facebook?",
  "choices":["Zuckerberg","Steve Job","Bill Gates"],
  "answer":"Zuckerberg"
}
];

function getRandomComputerChoice(choice) {
  const randomChoice = Math.floor(Math.random() * choice.length)

 if (randomChoice === 0){
     return choice[randomChoice].choices[0]
 } else if (randomChoice === 1){
   return choice[randomChoice].choices[1]
 } else {
    return choice[randomChoice].choices[2]
 }
  // const questionChoice = randomChoice.question
 
  // return questionChoice
  // return choice[randomChoice]
}
console.log(getRandomComputerChoice(questions))


Your browser information:

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

Challenge Information:

Build a Quiz Game - Build a Quiz Game

Hi. I can see you have only completed the computer choice so far.

With your console log I can see you have tested your function by passing the questions array. Test 8 states the getRandomComputerChoice function takes an array of the available choices as a parameter.

To test your function you need to pass in one of your choices arrays into your function and see if your function works by returning a random answer. If it doesn’t work you need to think how to fix it so it returns a random answer from the array.