Tell us what’s happening:
- You should have a function named getRandomQuestion that takes an array of questions as a parameter and returns a random question object from the array.
- You should have a function named getRandomComputerChoice that takes the array of the available choices as a parameter, and returns a random answer to the selected question.
- If the computer choice doesn’t match the answer, getResults should return The computer’s choice is wrong. The correct answer is: , where <correct-ans
Your code so far
const questions = [
{
category: "60s Movies",
question: "Which 1960 Alfred Hitchcock film features the infamous shower scene?",
choices: ["Vertigo", "Psycho", "The Birds"],
answer: "Psycho"
},
{
category: "60s Movies",
question: "Who played the lead role of Atticus Finch in the 1962 film, 'To Kill a Mockingbird'?",
choices: ["Gregory Peck", "Paul Newman", "James Stewart"],
answer: "Gregory Peck"
},
{
category: "60s Movies",
question: "What 1969 film starring Paul Newman and Robert Redford features the famous duo as outlaws?",
choices: ["Bonnie and Clyde", "The Wild Bunch", "Butch Cassidy and the Sundance Kid"],
answer: "Butch Cassidy and the Sundance Kid"
},
{
category: "60s Movies",
question: "Which 1968 Sci-fi film directed by Stanley Kubrick features the AI Hal 9000?",
choices: ["Blade Runner", "2001: A Space Odyssey", "Planet of the Apes"],
answer: "2001: A Space Odyssey"
},
{
category: "60s Movies",
question: "Sidney Poitier stars in which 1967 film alongside Katharine Hepburn and Spencer Tracy?",
choices: ["To Sir With Love", "Lilies of the Field", "Guess Who's Coming to Dinner"],
answer: "Guess Who's Coming to Dinner"
}
];
console.log(questions);
function getRandomQuestion(questions){
let randomIndex = Math.floor(Math.random() * questions.length);
let randomQuestion = questions[random];
return questions[randomIndex];
}
function getRandomComputerChoice(choices){
let randomIndex = Math.floor(Math.random() * choices.length);
let randomChoices = choices[random];
return[randomIndex];
}
function getResults(randomQuestion, randomChoices){
if(randomChoices === randomQuestion.answer){
return "The computer's choice is correct!";
}else{
return `The computer choice is wrong. The correct answer is ${randomQuestion.answer};`
}
}
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 Edg/136.0.0.0
Challenge Information:
Build a Quiz Game - Build a Quiz Game