Tell us what’s happening:
from function get random computer choices number 9 on the list its showing error but am unable to fix please help! anyone?
Your code so far
let questions=[
{
category : "Music",
question : "What model of Fender guitar did Jimi Hendrix play?",
choices : ["Telecaster", "Stratocaster", "Les Paul"],
answer : "Stratocaster",
},
{
category : "Sport",
question : "Which driver is currently winning the 2025 Formula 1 season?",
choices : ["Max Verstappen", "Charles Leclerc", "Oscar Piastri"],
answer : "Oscar Piastri",
},
{
category : "TV",
question : "Which Game Of Thrones character killed The Night King?",
choices : ["Arya Stark", "Jon Snow", "Jaime Lannister"],
answer : "Arya Stark",
},
{
category : "Food",
question : "Which food originated from Italy?",
choices : ["Curry", "Pasta", "Burritos"],
answer : "Pasta",
},
{
category : "Science",
question : "Which element has the symbol \"Au\" on the periodic table?",
choices : ["Mercury", "Silver", "Gold"],
answer : "Gold",
}
];
function getRandomQuestion (arr){
let randomIndex= Math.round(Math.random() * arr.length-1)
return arr[randomIndex]
}
let randomQuestion= getRandomQuestion(questions);
console.log(randomQuestion.question);
function getRandomComputerChoice(choicess){
let response=randomQuestion.answer;
return response
}
let response=getRandomComputerChoice(questions);
console.log(`The answer is: ${response}`)
let choice=randomQuestion.answer;
//console.log(`The answer is: ${choice}`)
function getResults(questions, altimateChoice){
if(questions===altimateChoice){
return "The computer's choice is correct!"
} else {
return `The computer's choice is wrong. The correct answer is: ${randomQuestion.answer}`
}
}
let reelAnswer=randomQuestion.answer;
let output=getResults(reelAnswer,choice)
console.log(output);
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game
https://www.freecodecamp.org/learn/full-stack-developer/lab-quiz-game/lab-quiz-game