Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

The code is not passing although the game seems to function properly. Am I doing something wrong or is there another way I need to code this in order to pass?

Your code so far

const questions = [
  {
    category: 'Padel',
    question: 'Who were the number 1 seeds for 2024?',
    choices:['tapia & coello', 'chingalan', 'lebron & dinenno'],
    answer: 'tapia & coello',
  },
  {
    category: 'Padel',
    question: 'Who is the nicest padel player?',
    choices:['agus', 'chingotto', 'paquito'],
    answer: 'chingotto',
  },
  {
    category: 'Padel',
    question: 'Who is the most controversial padel player?',
    choices:['tolito', 'lebron', 'galan'],
    answer: 'lebron',
  },
  {
    category: 'Padel',
    question: 'Who were the super pives?',
    choices:['stupa & dinenno', 'lebron & galan', 'chingotto & paquito'],
    answer: 'stupa & dinenno',
  },
  {
    category: 'Padel',
    question: 'Who were the super pivas?',
    choices:['delfi & bea', 'lebrona & galana', 'chingotta & paquita'],
    answer: 'delfi & bea',
  }
];

let randomQ;
const getRandomQuestion = () => {
  const randomNum = Math.round(Math.random() * 4);
   randomQ = randomNum;
   const randomQuestion = questions[randomNum].question;
   return randomQuestion
}
console.log(getRandomQuestion());

let computerChoice;
const getRandomComputerChoice = (randomQuestion) => {
const randomComputerChoice = questions[randomQuestion].choices[Math.round(Math.random() * 2)];
computerChoice = randomComputerChoice;
  return randomComputerChoice
}

console.log(getRandomComputerChoice(randomQ));

const getResults = () => {
  if (computerChoice === questions[randomQ].answer) {
    return "The computer's choice is correct!"
  } else {
    return `The computer's choice is wrong. The correct answer is: ${questions[randomQ].answer}`
  }
}
console.log(getResults());

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Build a Quiz Game - Build a Quiz Game

Which test out of the 12 is failing?

  1. You should have a function named getRandomQuestion that returns a random question object from the questions array.

This test is failing. Does that function return an object?

test 8, 9, 11 & 12 are failing

It returns a variable with the question (questions[randomNum].question) in it. I changed it to return “questions[randomNum].question” and it still fails the test.

You should have a function named getResults that takes the selected question object and the computer choice as its parameters

is that an object or a string? use typeof()

console.log(typeof(questions[randomNum].question))

Its a string. So if the object keys holds a string, how can I return the question (that is a string) as an object?

Return the entire object, not the string.

Each of the objects in the array is considered a question, or a “question object”.

  • getRandomQuestion should return a random question object from the questions array.

  • getRandomComputerChoice should take in the choices array of that random question object returned by getRandomQuestion and it should return a random element from the choices array it was passed.

  • getResults should take the two before mentioned return values, the random question object and the random element from the choices array (in that order), and use them for its return logic.

Awesome, thanks for your help!

1 Like

Finally got it, thank you so much!

1 Like

Hello, I am stuck too on step 8.
I have returned the entire object but still won’t be accepted.
My code produces the wanted result as i test it on VSC but i wish to know how you did to make it accepted. Thanks in advance

Hi there. Create your own topic to the challenge project using help button.

HI, thanks for your answer. I will try my best tonight starting over and I will use the help button by tomorrow since I am stuck for two days now .

1 Like