Tell us what’s happening:
My code does not pass the following tests, but i think my functions take as parameters and return what they are supposed to: 8. 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.
9. 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.
Your code so far
const questions = [
{
category: "Science",
question: "What planet is known as the Red Planet?",
choices: ["Mars", "Venus", "Jupiter"],
answer: "Mars"
},
{
category: "History",
question: "Who was the first president of the United States?",
choices: ["George Washington", "Abraham Lincoln", "Thomas Jefferson"],
answer: "George Washington"
},
{
category: "Geography",
question: "What is the capital of France?",
choices: ["Paris", "Madrid", "Rome"],
answer: "Paris"
},
{
category: "Math",
question: "What is 5 + 5?",
choices: ["10", "15", "20"],
answer: "10"
},
{
category: "Animals",
question: "What is the largest land animal?",
choices: ["Elephant", "Giraffe", "Rhinoceros"],
answer: "Elephant"
}
];
function getRandomQuestion(questions) {
return questions[Math.floor(Math.random() * questions.length)];
}
function getRandomComputerChoice(choices) {
return choices[Math.floor(Math.random() * choices.length)];
}
function getResults(question,choice){
if(question.answer === choice){
return "The computer's choice is correct!"
} else {
return "The computer's choice is wrong. The correct answer is: "+question.answer
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36 OPR/135.0.0.0
Challenge Information:
Build a Quiz Game - Build a Quiz Game