Tell us what’s happening:
Hello,
I am seeking for help as I am not able to pass the 11th step. The step is:
“11. Your getResults function should take the question object as the first parameter and the computer’s choice as the second parameter.”
I understand (or think) the problem is coming from my parameters but I can’t find why.
My getResults function has question and getRandomComputerChoice as parameters.
Thanking you in advance for any help you could provide.
Your code so far
const questions = [
{
category:"color",
question:"what is your favorite color?",
choices:["blue","pink","green"],
answer:"green",
},
{
category:"Pet?",
question:"what pet do you prefer?",
choices:["cat", "dog", "fish"],
answer:"dog",
},
{
category:"Hightech",
question:"what product do you use most?",
choices:["computer","laptop", "smartphone"],
answer:"computer",
},
{
category:"cooking?",
question:"What is your favorite food?",
choices:["Pizza","Pasta","Rice"],
answer:"Pasta",
},
{
category:"sports?",
question:"What is your favorite sport?",
choices:["football", "rugby","swimming"],
answer:"rugby",
}];
const getRandomNumber = (min, array) =>
Math.floor(Math.random() * (Math.floor(array.length) - Math.ceil(min)) + Math.ceil(min));
const getRandomQuestion = (questions) => questions[getRandomNumber(0,questions)];
const randomQuestion = getRandomQuestion(questions);
const getRandomComputerChoice = (arrayChoices) => arrayChoices[getRandomNumber(0, arrayChoices)];
const randomAnswer = getRandomComputerChoice(randomQuestion.choices);
const getResults = (question, getRandomComputerChoice) => {
if (question.answer.includes(getRandomComputerChoice)) {
return "The computer's choice is correct!";
} else {
return `The computer's choice is wrong. The correct answer is: ${question.answer}`;
}
};
console.log(randomQuestion);
console.log(randomAnswer);
console.log(getResults(randomQuestion, randomAnswer));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Challenge Information:
Build a Quiz Game - Build a Quiz Game