Build a Quiz Game - Build a Quiz Game

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
https://www.freecodecamp.org/learn/full-stack-developer/lab-quiz-game/lab-quiz-game

What do you think getRandomComputerChoice is here? Try logging it inside the function to see.

It’s a function and an object if I add a parameter “questions” ( getRandomComputerChoice(questions). I see what you want to say and I tried as follow to get a string:

let gRandomComputerChoice = getRandomComputerChoice(questions).answer;
and then updated the function:

const getResults = (question, gRandomComputerChoice) => {
if (question.answer.includes(gRandomComputerChoice)) {
return “The computer’s choice is correct!”;
} else {
return The computer's choice is wrong. The correct answer is: ${question.answer};
}
};

But still the same, I’m unable to pass the 11th step. All the others are ok.

Many thanks I figured out where the problem was ! Thanks for the input it helped me a lot (and adding one change as well).

If you see this, do you mind telling me what you did to fix your error? I’m seeing the same problem, but my steps 12 & 13 succeed, so I know I’m getting the correct values from the question object.

hi @iseanc , please create your own topic for your questions

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.