Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

Hello, Hello
Thank you for helping me out.

I am confused, or maybe I am mixing up my logic.

In the JavaScript Lab - Build a Quiz Game
I am not correctly completing 11 & 12.

#11 is asking for the getResults function to have the parameters declared a certain way. On line 56 I have declared the function, and the parameters to my understanding are in the right order. Does my issue have ot do with the call function of the gRandomQuestion variable ??

#12 I believe this issue will be correctl

Your code so far

const questions = [
  { // object 1....Woodstock
    category: "Music",
    question: "Where was the original Woodstock ??",
    choices: ["Bethel, NY", "Woodstock, IL", "Boston, MA"], 
    answer: "Bethel, NY"
  },
  { // object 2....Back to the Future
    category: "Movies",
    question: "Who was the original Marty McFly ??",
    choices: ["Christoper Llyod", "Michael J. Fox", "Eric Stoltz"],
    answer: "Eric Stoltz"
  },
  { // object 3....iPod
    category: "Technology",
    question: "When did the OG iPod release ??",
    choices: ["1998", "2001", "2003"],
    answer: "2001"
  },
  { // object 4....Pepsi
    category: "Drinks",
    question: "When did Pepsi debut their Soda ??",
    choices: ["1893", "1922", "1901"],
    answer: "1893"
  },
  { // object 5....Transformers
    category: "Pop Culture",
    question: "Who is the leader of the AutoBots ??",
    choices: ["Optimus Prime", "Bumble-Bee", "Sentinel Prime" ],
    answer: "Optimus Prime"
  },
  { // object 6....Robin
    category: "Pop Culture",
    question: "What is the identity of the second Robin ??",
    choices: ["Stephanie Brown", "Dick Grayson", "Jason Todd"],
    answer: "Jason Todd"
  }

];


function getRandomQuestion(questions) {
    let randomQuestionObj = Math.floor(Math.random() * questions.length);
    return questions[randomQuestionObj];
};
function getRandomComputerChoice(gRandomQuestion) {
    let random = Math.floor(Math.random() *gRandomQuestion.length);
    return gRandomQuestion[random];
};

//Function Calls 
let gRandomQuestion = getRandomQuestion(questions);
let computersChoice = getRandomComputerChoice(gRandomQuestion.choices);


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

let result=getResults(gRandomQuestion, computersChoice);


//console.log(`Question:: ${gRandomQuestion}`)
console.log(`Computer's choice:: ${computersChoice}`) // used to see the code n action
console.log(result);








Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:145.0) Gecko/20100101 Firefox/145.0

Challenge Information:

Build a Quiz Game - Build a Quiz Game

I think you shot yourself in the foot with your variable names.

function getResults(gRandomQuestion, computersChoice){
  if(computersChoice === getRandomQuestion.answer) {

What is gRandomQuestion ?
What is getRandomQuestion ?
What is getRandomQuestion.answer ?

Oh my…….I did not realize.
It was as simple.

The correction was as simple as correcting the if statement to state the right variable.
to use the variable gRandomQuestion

Thank you very much !!

1 Like

Careful with the names you give your variables. Make it very clear for yourself.