Tell us what’s happening:
I genuinely do not understand how getResults is supposed to work and how is supposed to take two parameters that depend on previous functions. Please advice I’m lost
Your code so far
const questions = [
{
category: "Geography",
question: "What is the capital of Japan?",
choices: ["Tokyo", "Berlin", "Panama"],
answer: "Tokyo"
},
{
category: "US History",
question: "Who was the first U.S. president?",
choices: ["Donald Trump", "George Washington", "Paul George"],
answer: "George Washington"
},
{
category: "Astronomy",
question: "What planet is known as the Red Planet?",
choices: ["Earth", "Mercury", "Mars"],
answer: "Mars"
},
{
category: "Sports",
question: "How many players are on a soccer field per side?",
choices: ["11", "12", "10"],
answer: "11"
},
{
category: "Biology",
question: "What gas do humans breathe in to survive?",
choices: ["Helium", "Oxygen", "Argon"],
answer: "Oxygen"
},
];
function getRandomQuestion (arr) {
let random = Math.floor(Math.random() * 5);
return arr[random]
}
function getRandomComputerChoice (arr) {
let random = Math.floor(Math.random() * 3);
return arr[random]
}
function getResults (obj, choice) {
obj = getRandomQuestion(questions);
choice = getRandomComputerChoice(questions[obj].choices)
if (choice === obj.answer) {
return `The computer's choice is correct!`
}
return `The computer's choice is wrong. The correct answer is: ${obj.answer}`
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game

