Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

Ive tried every way i can and have been studying and researching for days, but i can’t pass #11 - #14. Please help me.

Your code so far

const questions = [];

const q1 = {
  category: "music",
  question: "Who sing for Metallica?",
  choices: ["James Hetfield", "Dave Mustaine", "Dr. Joyce Brothers"],
  answer: "James Hetfield"
};

const q2 = {
  category: "history",
  question: "What year was JFK assassinated?",
  choices: ["1988", "1999", "1963"],
  answer: "1963"
};

const q3 = {
  category: "art",
  question: "Who painted the Mona Lisa?",
  choices: ["Van Gogh", "Da Vinci", "Monet"],
  answer: "Da Vinci"
};

const q4 = {
  category: "movies",
  question: "Who directed Batman Begins?",
  choices: ["Ron Livingston", "Barbara Bush", "Christopher Nolan"],
  answer: "Christopher Nolan"
};

const q5 = {
  category: "tv",
  question: "Who is the father of in the show The Simpsons?",
  choices: ["Ned", "Moe", "Homer"],
  answer: "Homer"
};

questions.push(q1, q2, q3, q4, q5);

const getRandomQuestion = (arr) => {
  const randomIndex = Math.floor(Math.random() * arr.length);
  return arr[randomIndex];
}

const randomQuestion = getRandomQuestion(questions);

const getRandomComputerChoice = (arr) => {
  const randomIndex = Math.floor(Math.random() * arr.length);
  return arr[randomIndex];
};

const finalQuestion = randomQuestion.question;
const finalCompChoice = getRandomComputerChoice(randomQuestion.choices)

const getResults = (finalQuestion, finalChoice) => {
  if (finalChoice === randomQuestion.answer) {
    return `The computer's choice is correct!`
  } else {
    return `The computer's choice is wrong. The correct answer is: ${randomQuestion.answer}`
  }
}
const result = getResults(finalQuestion, finalCompChoice);

console.log(finalQuestion);
console.log(finalCompChoice);
console.log(result);


Your browser information:

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

Challenge Information:

Build a Quiz Game - Build a Quiz Game

Welcome to the forum @nicholauswild

image

Syntax highlighting is showing you are not using the first parameter.

Happy coding

I changed that but the same tests are still failing.

const getResults = (finalQuestion, finalChoice) => {
  console.log(finalQuestion);
  console.log(finalCompChoice);
  if (finalChoice === randomQuestion.answer) {
    return `The computer's choice is correct!`
  } else {
    return `The computer's choice is wrong. The correct answer is: ${randomQuestion.answer}`
  }
}
const result = getResults(finalQuestion, finalCompChoice);


console.log(result);

console.log() does not count as “using” it.

Why is it a parameter? Presumably you need it for something

Thank you. that helped a lot and i was on the verge of quitting. hahaha

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.