Tell us what’s happening:
My code is working fine but does not pass the test
Your code so far
const questions = [{
category: "Food",
question: "What is my favorite food?",
choices: ["Pizza", "Fried Chicken", "Sushi"],
answer: "Pizza"
}, {
category: "Drink",
question: "What is my favorite drink?",
choices: ["Water", "Coke", "Alcohol"],
answer: "Water"
}, {
category: "Phone",
question: "What is my phone brand?",
choices: ["Huawei", "Apple", "Samsung"],
answer: "Samsung"
}, {
category: "Laptop",
question: "What is my laptop brand?",
choices: ["Acer", "Asus", "Mac"],
answer: "Asus"
}, {
category: "Math",
question: "What is the square root of 81?",
choices: ["3", "7", "9"],
answer: "9"
}];
let randObj = Math.floor((Math.random() * questions.length))
function getRandomQuestion(randQuestion){
return randQuestion[randObj].question;
}
console.log(getRandomQuestion(questions));
function getRandomComputerChoice(randChoice){
return randChoice[randObj].choices[Math.floor((Math.random() * 3))];
}
let compChoice = getRandomComputerChoice(questions);
console.log(compChoice)
function getResults(){
if (compChoice == questions[randObj].answer){
return "The computer's choice is correct!"
}
else {
return `The computer's choice is wrong. The correct answer is: ${questions[randObj].answer}`
}
}
console.log(getResults());
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game