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