Tell us what’s happening:
Having issue on the 8th requirement
My code passed the rest expect the no 8
Your code so far
const questions = [];
const question1 = {
category: 'Science',
question: "What is the outermost layer of Earth's atmosphere called?",
choices: ["Stratosphere", "Troposphere", "Exosphere"],
answer: "Exosphere"
};
const question2 = {
category: 'General Knowledge',
question: "Which of the following is considered the world's fastest bird?",
choices: ["Peregrine Falcon", "Ostrich", "Albatross"],
answer: "Peregrine Falcon"
};
const question3 = {
category: 'Science',
question: 'Which element have the chemical symbol \"K\"?',
choices: ["Calcium", "Krypton", "Potassium"],
answer: "Potassium"
};
const question4 = {
category: 'History',
question: 'Who developed the theory of heliocentrism, which states that the Earth revolves around the sun?',
choices: ["Galileo Galilei", "Nicolaus Copernicus", "Johannes Kepler"],
answer: "Nicolaus Copernicus"
};
const question5 = {
category: 'Biology',
question: 'What is the Latin name for a giant panda?',
choices: ["Felis catus", "Ailuropoda melanoleuca", "Pan troglodytes"],
answer: "Ailuropoda melanoleuca"
};
questions.push(question1, question2, question3, question4, question5);
function getRandomQuestion(questions) {
if (questions.length === 0) {
console.log("No more questions!");
return null;
} else {
const randomIndex = Math.floor(Math.random() * questions.length);
const question = questions[randomIndex];
return question;
}
};
//console.log(getRandomQuestion(questions));
function getRandomComputerChoice(choices) {
const randomIndex = Math.floor(Math.random() * choices.length);
const choice = choices[randomIndex];
return choice;
};
//console.log(getRandomComputerChoice(questions));
function getResults(questionObj,computerChoices){
if (computerChoices.choice === questionObj.ans) {
return "The computer's choice is correct!";
} else {
return "The computer's choice is wrong. The correct answer is: " + questionObj.answer;
}
};
console.log(getResults(getRandomQuestion,getRandomComputerChoice));
console.log(getResults(getRandomQuestion,getRandomComputerChoice));
Your browser information:
User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/141.0.7390.96 Mobile/15E148 Safari/604.1
Challenge Information:
Build a Quiz Game - Build a Quiz Game