Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

My code works, but still somehow doesn’t pass tests 9, 11, 13 & 14, not sure why when the code works?

Your code so far

let questions = [];

let q1 = {
  category: "Entertainment",
  question: "Cher won an Oscar for her role in which film?",
  choices: ["Burlesque", "Moonstruck", "Mermaids"],
  answer: "Moonstruck"
}

let q2 = {
  category: "Nature",
  question: "What is a group of Hyenas called?",
  choices: ["A Cackle", "A Pride", "A Gathering"],
  answer: "A Cackle"
}

let q3 = {
  category: "Arts",
  question: "According to Exodus, what is the fifth plague of Egypt?",
  choices: ["Diseased livestock", "Water turned to Blood", "Swarms of Locusts"],
  answer: "Diseased livestock"
}

let q4 = {
  category: "Science",
  question: "How many moons does Mars have?",
  choices: ["None", "One", "Two"],
  answer: "Two"
}

let q5 = {
  category: "History",
  question: "Where was ballet invented?",
  choices: ["Italy", "France", "Russia"],
  answer: "Italy"
}

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

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

let randomQ = getRandomQuestion(questions);
let question = randomQ.question

function getRandomComputerChoice(arr) {
  let length = randomQ['choices'].length;
  let randomNum = Math.floor(Math.random() * length);
  return randomQ.choices[randomNum]
}

let answer = getRandomComputerChoice(questions);

function getResults(question, answer) {
  if (answer === randomQ.answer) {
    return "The computer's choice is correct!"
  } else {
    return "The computer's choice is wrong. The correct answer is: " + randomQ.answer
  }
};

console.log(question);
console.log(answer);
console.log(getResults(question, answer));

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

Challenge Information:

Build a Quiz Game - Build a Quiz Game

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.

Are you passing a question object to getResults?

You should have a function named getRandomComputerChoice that takes the array of the available choices as a parameter

Are you passing an array of available choices to getRandomComputerChoice?

Redid the whole code and passed all the tests :slight_smile:

1 Like