Tell us what’s happening:
Hi there!
I’ve passed all the test except test 4.
- The question key should have the value of a string representing a question.
My code is working fine though I don’t know what’s wrong. Can anyone please give me a hint?
Your code so far
const questions = [
{
category: "Human Anatomy",
question: "What is the largest organ in the body?",
choices: ["Skin", "Lungs", "Large Intestin"],
answer: "Skin"
},
{
category: "Animal",
question: "What is the largest animal?",
choices: ["Elephant", "Giraffe", "Whale"],
answer: "Whale"
},
{
category: "Astronomy",
question: "What is planet is the closest to the sun?",
choices: ["Venus", "Mars", "Mercury"],
answer: "Mercury"
},
{
category: "Mathematics",
question: "This value is, by definition, the smallest prime number.",
choices: ["2", "1", "4"],
answer: "2"
},
{
category: "Geography",
question: "What is the highest mountain above sea level?",
choices: ["Mauna Kea", "Mount Everest", "Mount Fuji"],
answer: "Mount Everest"
}
];
function getRandomQuestion(arrQuestions) {
const randomQuestion = Math.floor(Math.random() * arrQuestions.length);
return arrQuestions[randomQuestion];
}
function getRandomComputerChoice(arrChoices) {
const randomAnswer = Math.floor(Math.random() * arrChoices.length);
return arrChoices[randomAnswer];
}
const randomQuestion = getRandomQuestion(questions);
const randomAnswer = getRandomComputerChoice(randomQuestion.choices);
function getResults(question, answer) {
if(question.answer === answer) {
return "The computer's choice is correct!";
} else {
return `The computer's choice is wrong. The correct answer is: ${question.answer}`
}
}
console.log(getResults(randomQuestion, randomAnswer));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game