Tell us what’s happening:
checked the output, its fine but stuck with this case
“Your getResults function should take the question object as the first parameter and the computer’s choice as the second parameter”
any help will be appreciated !!
Your code so far
let questions = [
{
category: "PCo",
question: "fav color ?",
choices: ['Red', 'Black', 'Both'],
answer: 'Red'
},
{
category: "PCa",
question: "Fav car ?",
choices: ['Honda', 'BMW', 'both'],
answer: 'BMW'
},
{
category: "PB",
question: "Fav brand ?",
choices: ['Amazon', 'Google', 'Both'],
answer: 'Both'
},
{
category: "PF",
question: "Fav fruit ?",
choices: ['Apple', 'Grapes', 'Mango'],
answer: 'Mango'
},
{
category: "PH",
question: "fav hobby ?",
choices: ['Singing', 'Coding', 'Both'],
answer: 'Both'
}
]
function getRandomQuestion(questionsArr){
return questionsArr[Math.floor(Math.random()*questionsArr.length)];
}
function getRandomComputerChoice(choicesArr){
return choicesArr[Math.floor(Math.random()*choicesArr.length)];
}
function getResults(question, computersChoice){
if(question["answer"] == computersChoice){
console.log("The computer's choice is correct!");
}else{
console.log(`The computer's choice is wrong. The correct answer is: ${question["answer"]}`);
}
}
let randomQuestion = getRandomQuestion(questions);
console.log(randomQuestion);
let computerChoice = getRandomComputerChoice(randomQuestion["choices"]);
console.log(computerChoice);
getResults(randomQuestion, computerChoice);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game