Tell us what’s happening:
Hi! I’m stuck at step 9 even though the console log is showing that code is working fine: a question is being selected and it also gives an answer selected from the choices of the same object.
Your code so far
const questions = [
{category:"Books",
question: "Who wrote The Chronicles of Narnia?",
choices: ["Lewis", "Tolkien", "Rowling"],
answer: "Lewis",
}, {category:"Sports",
question: "Who is considered to be the GOAT in football?",
choices: ["CR7", "Ronaldinho", "Messi"],
answer: "Messi",
}, {category:"Videogames",
question: "What series is the spell Firaga from?",
choices: ["FF", "Baldur's Gate", "The Witcher"],
answer: "FF",
}, {category:"Characters",
question: "What's the name of Phineas and Pherb's pet?",
choices: ["Araku", "Pluto", "Perry"],
answer: "Perry",
}, {category:"Films",
question: "Best trilogy eva?",
choices: ["LoTR", "Shrek", "Harry Potter"],
answer: "LoTR",
}];
const getRandomQuestion = function(arr) {
let random = Math.floor(Math.random() * arr.length);
return arr[random]
};
let randomQuestion = getRandomQuestion(questions);
console.log(randomQuestion)
const getRandomComputerChoice = function(arr) {
let random = Math.floor(Math.random() * 3);
return arr['choices'][random];
};
let computerChoice = getRandomComputerChoice(randomQuestion);
console.log(computerChoice);
const getResults = (question, choice) => {
if (choice === question.answer) {
return `The computer's choice is correct!`
} else {
return `The computer's choice is wrong. The correct answer is: ${question.answer}`
}
}
let results = getResults(randomQuestion, computerChoice);
console.log(results)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game