Tell us what’s happening:
I’m testing as I go, so anything past 9 isn’t of concern to me yet. However, my code performs the task that test 9 requires but the test shows me failing. Why isn’t my code passing that test?
Your code so far
const questions = [
{
category: "sports",
question: "Who is the NBA GOAT?",
choices: ["LeFlop Blames", "Michael Jordan", "Wilt Chamberlain"],
answer: "Michael Jordan"
},
{
category: "history",
question: "What was Napoleon's last battle?",
choices: ["Austerlitz", "Gettysburg", "Waterloo"],
answer: "Waterloo"
},
{
category: "science",
question: "How many electrons are present in a neutral radium atom?",
choices: ["75", "111", "88"],
answer: "88"
},
{
category: "movies",
question: "Who played Rick Blaine in Casablanca?",
choices: ["Humphrey Bogart", "James Cagney", "Cary Grant"],
answer: "Humphrey Bogart"
},
{
category: "music",
question: "What famous guitarist and band leader played a famous solo on Michael Jackson's Beat It?",
choices: ["Steve Vai", "BB King", "Eddie Van Halen"],
answer: "Eddie Van Halen"
}
];
function getRandomQuestion(questions) {
let randomQuestion = questions[(Math.floor(Math.random() * questions.length))];
return randomQuestion;
}
const randomQuestion = getRandomQuestion(questions);
console.log(randomQuestion)
function getRandomComputerChoice(choices) {
choices = randomQuestion.choices;
let randomChoice = choices[(Math.floor(Math.random() * choices.length))];
return randomChoice;
}
const randomAnswer = getRandomComputerChoice();
console.log(randomAnswer)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game