Build a Quiz Game- JavaScript

The following code returns the two expected outcomes randomly. I’m unsure what I’m messing up on.



const questions = []
let question1 = {
  category: "html",
  question: "Question 1?",
  choices: ["Choice 1", "Choice 2", "answer"],
  answer: "answer"
};

let question2 = {
  category:"CSS",
  question:"Question 2?",
  choices: ["Choice 1", "Choice 2", "answer"],
  answer: "answer"
}

let question3 = {
  category:"Void Elements",
  question:"Question 3?",
  choices: ["Choice 1", "Choice 2", "answer"],
  answer: "answer"
}
let question4 = {
  category:"Strings",
  question:"Question 4?",
  choices: ["Choice 1", "Choice 2", "answer"],
  answer: "answer"
}
let question5 = {
  category:"Arrays",
  question:"Question 5?",
  choices: ["Choice 1", "Choice 2", "answer"],
  answer: "answer"
}
questions.push(question1, question2, question3, question4, question5,);
let qIndex = Math.floor(Math.random() * questions.
length);  

function getRandomQuestion(questions){
 return questions[qIndex];
};

function getRandomComputerChoice(choices){
let rccIndex = Math.floor(Math.random() * questions[qIndex].choices.length);
return questions[qIndex].choices[rccIndex];
}

console.log()
let qObject = getRandomQuestion(questions);
let cChoice = getRandomComputerChoice()
function getResults(qObject, cChoice){
if(qObject.answer === cChoice){
return "The computer's choice is correct!";
}else{
return `The computer's choice is wrong. The correct answer is: ${qObject.answer}`
}

};
console.log(getResults(qObject, Choice));

Apologies, It’s my first time using the forums, I’m able to pass every check aside from the getRandomComputerChoice(choices) function check. I’m pretty confused as I’m able to pass the getResults function check.

ReferenceError: Choice is not defined

You have an error displaying in the console. Please fix that first.

You are missing an argument in this function call.

1 Like

Thank you so much for all of your help!