Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

I’m failing on the first test that tells me to create an array named questions. I have done that but it wont let me pass, I cant get why

Your code so far


const questions = [
  {
    category: "Christianity",
    question:"How old was Jesus when He got baptized?",
    choices: ["7y","12y","30y"],
    answer: "30y"
  },
  {
    category: "Time",
    question:"How long is the 5 second rule in seconds",
    choices: ["5s","50s","30s"],
    answer: "5s"
  },
  {
    category: "Programming",
    question:"Are you a programmer?",
    choices: ["Yes","No","Not sure"],
    answer: "Yes"
  },
  {
    category: "Eating",
    question:"What flour is chapatti made of?",
    choices: ["Maize","Wheat","Barley"],
    answer: "Wheat"
  },
  {
    category: "JavaScript",
    question:"What am I creating?",
    choices: ["objects","loops","Variables"],
    answer: "objects"
  }
];

function getRandomQuestion(questions){
  const randomNumber = Math.floor(Math.random() * questions.length)

  return questions[randomNumber]
}

 const randomQuestion = getRandomQuestion()

function getRandomComputerChoice(choices){
  const randomNumber = Math.floor(Math.random() * choices.length)
  return randomQuestion.choices[randomNumber]
}

const randomComputerAnswer = getRandomComputerChoice()

const randomAnswer = randomQuestion.answer

function getResults(randomComputerAnswer,randomAnswer){
if(randomComputerAnswer == randomAnswer){
  return "The computer's choice is correct!"
}
else{
  return `The computer's choice is wrong. The correct answer is: ${randomQuestion.answer} `
}
}


Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Build a Quiz Game - Build a Quiz Game

I would look at the error message in the console

It gives TypeError: Cannot read properties of undefined (reading ‘length’). I’m also trying to log the array onto the console but it gives nothing. even the typeof method is not working. something is wrong with my array but I’ve checked multiple times but can’t seem to see the problem

Here’s your function’s declaration.

And here’s where you’re calling it.

What are you missing in your function call?

You should have a function named getResults that takes the question object as the first parameter and the computer’s choice as the second parameter.

Does your code meet the requirements of User Story #9?

Thanks I’ve seen the problem was that I had not passed any arguments to my function call. For requirement 9 I have seen the error and changed it as my function was using the question array instead of the choices array. My final code looks like this:

removed by moderator

Good job on finding the issues in your code, but please don’t post a working solution.

sorry. Thanks for the help

No worries. You’re new here, so you get a pass. :grinning_face:

fCC is trying to cut back on the number of spoiler and full working solutions posted on the forum, focusing instead on guiding campers to troubleshoot their own code…an important skill out in the wild.