Tell us what’s happening:
Test case 8 is not passing. The function getRandomQuestion does return a random object but, it still won’t pass.
Your code so far
let questions = [];
let question1 = {
category: 'Animals',
question: 'What kind of animal has a meat only diet?',
choices: ["Omnivore", "Meat-Eater", "Carnivore"],
answer: "Carnivore",
}
let question2 = {
category: 'Automotive',
question: "What type of engines do gasoline vehicles have?",
choices: ["Inline-4", "Combustible-engine", "Combustion-engine"],
answer: "Combustion-engine",
}
let question3 = {
category: 'Coding',
question: "What is the best language to learn?",
choices: ["JavaScript", "Pytherium", "SEA++"],
answer: "JavaScript",
}
let question4 = {
category: 'Scripture',
question: "Who is Jesus?",
choices: ["A cool dude", "Prophet", "the Word"],
answer: 'the Word',
}
let question5 = {
category: 'Health',
question: "On average, how many hours of sleeps is recommended?",
choices: ["10 hours", "8 hours", "What is sleep?"],
answer: "8 hours",
}
questions.push(question1, question2, question3, question4, question5)
function getRandomQuestion(questions) {
return questions && questions.length !== 0 ? questions[Math.floor(Math.random() * questions.length)] : null;
};
function getRandomComputerChoice(choices) {
return choices && choices.length !== 0 ? choices[Math.floor(Math.random() * (choices.length))] : null;
};
function getResults(question, choice) {
return choice == question.answer ? "The computer's choice is correct!" : `The computer's choice is wrong. The correct answer is: ${question.answer}`
}
let question = getRandomQuestion(questions);
let choice = getRandomComputerChoice(question.choices);
let result = getResults(question, choice);
console.log(question);
console.log(choice);
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/131.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game