Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

code works but can pass step 13. Not sure what it wants?

Your code so far

const questions = [
  {
  category: "color",
  question: "What is my favorite color?",
  choices: ["Blue", "Red", "Purple"],
  answer: "Purple",
 },
 {
  category: "Birthplace",
  question: "Which country was I born in?",
  choices: ["America", "Germany", "Norway"],
  answer: "Germany",
 },
{
  category: "Video Games",
  question: "What is my favorite video game franchise?",
  choices: ["Call of Duty", "Bioshock", "Dark Souls"],
  answer: "Dark Souls",
 },
 {
  category: "Anime",
  question: "What is my favorite anime?",
  choices: ["Clannad", "Attack on Titan", "Sword Art Online"],
  answer: "Clannad",
 },
 {
  category: "MCU/DCU",
  question: "Who is my favorite Marvel/ DC character?",
  choices: ["Deadpool", "Dr. Manhattan", "Superman"],
  answer: "Dr. Manhattan",
 },
];

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

function getRandomComputerChoice(choices) {
let randomC = Math.floor(Math.random() * choices.length);
let computerChoice = choices[randomC];
return computerChoice;
};

let randQuest = getRandomQuestion(questions)

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36

Challenge Information:

Build a Quiz Game - Build a Quiz Game

what is step 13 asking? and which lines are doing that?

still super confused? what do you mean lines? like the strings? or the if else?

return `The computer's choice is wrong. The correct answer is: ${randQuest.answer}`;

Are you sure you want randQuest.answer here?

it’s the only way i can get the answer to display to console? otherwise it keeps returning undefined.

When you run the code or when the tests run? If it is undefined when you run it, it is because you are not providing it the correct thing.

Anyway, quest.answer is the correct answer, is it not? So that is what you should use.

i tried that before and it didnt work. So i went and adjusted the getRandomQuestion function but now step 8 fails.

function getRandomQuestion(questions) {
let random = Math.floor(Math.random() * questions.length);
let randomQuestion = questions[random].question;
return randomQuestion;
};

function getRandomComputerChoice(choices) {
let randomC = Math.floor(Math.random() * choices.length);
let computerChoice = choices[randomC];
return computerChoice;
};

let randQuest = getRandomQuestion(questions)

function getResults(quest, compChoice) {
if (compChoice === quest.answer) {
return “The computer’s choice is correct!”;
} else {
return The computer's choice is wrong. The correct answer is: ${quest.answer};
}
}

because now it is not returning an object anymore

so i got it to pass fully but when i log it to the console the answer is still undefined… is it supposed to be?

what are you trying to log?

console.log(getRandomQuestion(questions));
console.log(getRandomComputerChoice(questions));
console.log(getResults(getRandomQuestion, getRandomComputerChoice));

what is that last line? what are you passing to the function?

I think I’m confused as to what to pass to the parameters for the getResult function when I log it? i tried all sorts of stuff but this is the only one that didn’t throw an error.

what do you want to pass to it?

the output of the random choice and the random question functions i believe?

and how do you get the output of a function?

to me it looks like you are passing the functions themselves, not their outputs here