Tell us what’s happening:
Tests 8, 9, 11, 13, and 14 are returning false. I need a little help. The code works perfectly fine but the tests just aren’t getting cleared.
Your code so far
const questions = [
{
category: "astronomy",
question: "What does astronomy study?",
choices: ["living organisms", "weather", "space objects"],
answer: "space objects"
},
{
category: "country area",
question: "Which country is the largest by area?",
choices: ["Russia", "USA", "Canada"],
answer: "Russia"
},
{
category: "leap year",
question: "How many days in a leap year?",
choices: ["365", "366", "364"],
answer: "366"
},
{
category: "chemical symbol",
question: "Which chemical element has the symbol O?",
choices: ["Gold", "Ozone", "Oxygen"],
answer: "Oxygen"
},
{
category: "largest organ",
question: "What is the largest organ in the human body?",
choices: ["skin", "heart", "liver"],
answer: "skin"
},
];
let random = Math.floor(Math.random() * questions.length);
let randoans = questions[random].answer;
let answer = randoans;
function getRandomQuestion(array) {
return array[random].question;
};
let randoquest = getRandomQuestion(questions);
function getRandomComputerChoice(array) {
let randoc = Math.floor(Math.random() * 3);
return array[random].choices[randoc];
};
let randocho = getRandomComputerChoice(questions);
function getResults(question, choice) {
if (choice === answer) {
return "The computer's choice is correct!";
} else {
return `The computer's choice is wrong. The correct answer is: ${answer}`;
};
};
let result = getResults(randoquest, randocho);
console.log(randoquest);
console.log(randocho);
console.log(result);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0
Challenge Information:
Build a Quiz Game - Build a Quiz Game