Tell us what’s happening:
I cannot pass the ‘11. Your getResult function should take the question object as the first parameter and the computer’s choice as the second parameter.’ and ‘12. If the computer choice matches the answer. The getResults should return “The computer’s choice is correct!”’. Please help.
Your code so far
const questions = [
{
category: "Culinary Arts",
question: "Which of these ingredients is essential for making a traditional Filipino 'caramel' or 'yema' icing?",
choices: ["Whipping Cream", "Condensed Milk", "Cream Cheese"],
answer: "Condensed Milk"
},
{
category: "Computing",
question: "Which of these is popular Linux desktop environment known for its high level of customization and modern features?",
choices: ["KDE Plasma", "DirectX", "NTFS"],
answer: "KDE Plasma"
},
{
category: "Web Development",
question: "In CSS, which layout module is designed for creating complex two-dimensional layouts using rows and columns?",
choices: ["Flexbox", "Float","Grid"],
answer: "Grid"
},
{
category: "Space and Astronomy",
question: "Which is the largest planet in our solar system?",
choices: ["Saturn", "Jupiter", "Neptune"],
answer: "Jupiter"
},
{
category: "Pop Culture",
question: "In the film The Matrix, what color pill does Neo take to see the truth?",
choices: ["Blue", "Green", "Red"],
answer: "Red"
}
]
const getRandomQuestion = (questions) => {
const newQuestion = Math.floor(Math.random() * questions.length)
return questions[newQuestion]
}
const randomQuestion = getRandomQuestion(questions)
const choices = randomQuestion.choices
const getRandomComputerChoice = (choices) => {
const randomChoice = Math.floor(Math.random() * choices.length)
return choices[randomChoice]
}
const computerChoice = getRandomComputerChoice(choices)
const correctAnswer = randomQuestion.answer
const getResults = (randomQuestion, computerChoice) => {
if (randomQuestion !== computerChoice) {
return `The computer's choice is wrong. The correct answer is: ${randomQuestion.answer}`
} else {
return `The computer's choice is correct!`
}
}
console.log(randomQuestion)
console.log(computerChoice)
console.log(getResults(randomQuestion, computerChoice))
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 Edg/146.0.0.0
Challenge Information:
Build a Quiz Game - Build a Quiz Game