Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

here i’ve problem with getRandomComputerChoice function
which i should get get random choice from the choices array
but when i try do that i can’t pass its test
although i get good results on the console
what should i do ?
any hint please

Your code so far

const questions = [
  {
    category: 'sports',
    question: 'Who is the greatest footballer in africa ?',
    choices: ['M.Abo trika', 'H.Shehata', 'M.Elkhateeb'],
    answer: 'M.Abo trika',
  },
  {
    category: 'sports',
    question: 'Who is the greatest footballer in Europe ?',
    choices: ['Messi', 'C.Ronaldo', 'Ibrahimovic'],
    answer: 'Messi',
  },
  {
    category: 'sports',
    question: 'Who is the greatest footballer in Latin America ?',
    choices: ['Batistuta', 'Ronaldo', 'Romario'],
    answer: 'Romario',
  },
  {
    category: 'sports',
    question: 'Who is the greatest footballer in America ?',
    choices: ['Donovan', 'Kawalenko', 'Corrales'],
    answer: 'Donovan',
  },
  {
    category: 'policy',
    question: 'Who is the greatest politican in Egypt ?',
    choices: ['Naguib', 'Sadat', 'Mubarak'],
    answer: 'Mubarak',
  },
]

const getRandomQuestion = (arrOfQuestions) => {
  return arrOfQuestions[Math.floor(Math.random() * arrOfQuestions.length)]
}

// console.log(getRandomQuestion(questions))    

const getRandomComputerChoice = (avChoices) => {

  let random5 = Math.floor(Math.random() * avChoices.length)
  let random3 = Math.floor(Math.random() * 3)
  return avChoices[random5].choices[random3]        
}
  
const getResults = (question, comChoice) => {
  return comChoice
}

console.log(getRandomComputerChoice(questions))

// console.log(getResults(getRandomQuestion(questions), getRandomComputerChoice(questions.choices)))
        

Your browser information:

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

Challenge Information:

Build a Quiz Game - Build a Quiz Game

I would double check what the input to this function is supposed to be.

a random choice from the array of choices from random question object ?

That is the input to the getRandomComputerChoice function according to the instructions?

yes
here in the user story number 8
it says:
8. 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.

So, what part of that says what the input for the getRandomComputerChoice function is?

that’s what iam not sure about,
should it depends on the pre function getRandomQuestion function ??

This line you copied from the instructions says what the input for the getRandomComputerChoice function is:

but how can i get to this choices array from the right way ?!
this lab i had passed before but i come to train back
so i can train my muscles harder
something like active recall and spaced repitition
as i remember

I don’t understand your question.

In order to write this function correctly, you need to know what the expected input will be. I’m not sure if you know exactly what the input to this function is supposed to be?

limme guess ?
should it depend on another function or i should handle it manually ?

You do not need to guess. You need to read the user story 8 that you quoted.

What does this user story say is the input to the getRandomComputerChoice function?

but how can i pass the array of choices directly i need to get random question object first then i get the array of choices from that question then i get random choice from these choices array !!

should i only get random array of choices from the 5 questions objects then i get a random choice from it ?

There are two separate things you are mixing together.

  1. You need to understand what the correct input to the function is so you can use that input correctly inside of the function

  2. You need to understand what the correct input to the function is so that you can call the function correctly

In both cases, first you need to identify and say what the correct input is first.

So, what is the correct input to this function according to the user story?

i think it should be an array of available choices and a random choice from that array ?

Please. Please. Please say what the input to this function is supposed to be.

a random choice from the array of available choices ?

That’s not quite right. How can the input be both an array of available choices and a pick from that array at the same time?

The input is the thing that goes into the function. Don’t confuse it with the output, which is the thing that comes out of the function.