Tell us what’s happening:
here is my problem
11. Your getResults function should take the question object as the first parameter and the computer’s choice as the second parameter.
Failed:
12. If the computer choice matches the answer, getResults should return The computer’s choice is correct!
and how to solve them? i think my function getResults already right ![]()
Your code so far
const questions = [
{
category: "Food",
question: "Apa bahan utama pembuatan keju?",
choices: ["Susu", "Gandum", "Kedelai"],
answer: "Susu"
},
{
category: "Cooking",
question: "Teknik memasak dengan uap air disebut?",
choices: ["Menggoreng", "Mengukus", "Membakar"],
answer: "Mengukus"
},
{
category: "Nutrition",
question: "Vitamin apa yang banyak terkandung dalam jeruk?",
choices: ["Vitamin A", "Vitamin B", "Vitamin C"],
answer: "Vitamin C"
},
{
category: "Food",
question: "Mana yang merupakan buah tropis?",
choices: ["Apel", "Mangga", "Stroberi"],
answer: "Mangga"
},
{
category: "Cooking",
question: "Alat yang digunakan untuk membalik masakan adalah?",
choices: ["Sutil/Spatula", "Panci", "Cobek "],
answer: "Sutil/Spatula"
}
];
function getRandomQuestion(questionsArray) {
const randomIndex = Math.floor(Math.random() * questionsArray.length);
return questionsArray[randomIndex];
}
function getRandomComputerChoice(choicesArray) {
const randomIndex = Math.floor(Math.random() * choicesArray.length);
return choicesArray[randomIndex];
}
function getResults(question, computerChoice) {
const correctAnswer = question.answer;
if(computerChoice === correctAnswer) {
return "The computer's choice is correct!";
} else {
return `The computer's choice is wrong. The correct answer is: ${correctAnswer}`;
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game