Tell us what’s happening:
Hi there,
I am stuck on returning a result from step 9. I don’t quite know how to use the correct parameters for the function in order to call the function with an object of a random question.
When I console log the variables I have created for each function, I get the correct response but can’t quite make them work in the final function.
Some pointers in the right direction would be much appreciated.
Your code so far
const questions= [
{category: "colours" ,
question: "Colour of the kiwi fruit is?",
choices: ["red", "green", "blue"],
answer: "green"},
{category: "continent" ,
question: "What continent is Nigeria in?",
choices: ["America", "Africa", "Europe"],
answer: "Africa"},
{category: "Foods" ,
question: "What is a Tomato?",
choices: ["Vegetable", "Protein", "Fruit"],
answer: "Fruit"},
{category: "Cats" ,
question: "What is the world's biggest cat?",
choices: ["Lion", "Tiger", "Lynx"],
answer: "Tiger"},
{category: "population" ,
question: "How many billion people are there in the world?",
choices: ["7", "8", "9"],
answer: "8"},
]
function getRandomQuestion(questions){
let numberIndex= (Math.floor(Math.random()*questions.length))
let randomQuestion= questions[numberIndex]
return randomQuestion
}
const listChoices = getRandomQuestion(questions).choices
function getRandomComputerChoice(listChoices){
let numberIndex= (Math.floor(Math.random()*listChoices.length))
let randomAnswer= listChoices[numberIndex]
return randomAnswer
}
const randomQuery= getRandomQuestion(questions)
const computerResponse= getRandomComputerChoice(randomQuery.choices)
const correctResponse= randomQuery.answer
function getResults(randomQuery, computerResponse){
if (computerResponse === computerResponse)
return `The computer's choice is correct!`
else return `The computer's choice is wrong. The correct answer is: ${correctResponse}`
}
getResults()
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0
Challenge Information:
Build a Quiz Game - Build a Quiz Game