Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

Issue on Q.11 - Im passing the questions object and the choice string but it doesn’t pass

Your code so far

const questions = [
  {
  category:"Movies",
  question:"Which movie did have a green character with a yellow suit and green face ?",
  choices: ["Grinch", "Zoro","The mask"],
  answer:"The mask"
}, {
  category:"Buildings",
  question:"What is the landmark building of the western civilization?",
  choices: ["when", "why","The Parthenon"],
  answer:"The Parthenon"
}, {
  category:"Bikes",
  question:"what is a classic road bike?",
  choices: ["when", "why","A Harley-Davidson"],
  answer:"A Harley-Davidson"
}, {
  category:"Movies",
  question:"what movie pictured a historic ship?",
  choices: ["when", "why","The titanic"],
  answer:"The titanic"
}, {
  category:"Food",
  question:"what is your favorite dish?",
  choices: ["when", "why","Pasta"],
  answer:"Pasta"
}
];

function getRandomQuestion(questions){
  let randInt = Math.floor(Math.random() * questions.length);
  return questions[randInt];
}
function getRandomComputerChoice(choices) {
  let randInt = Math.floor(Math.random() * choices.length);
  return choices[randInt];
}
function getResults(question, choice){
  console.log(typeof question);
  console.log("///////////////");
  console.log(typeof choice);
  console.log("///////////////");

  if (choice === question.answer){
    return"The computer's choice is correct!";
  }else{
    `The computer's choice is wrong. The correct answer is: ${question.answer}`;
  }
}

let question = getRandomQuestion(questions);
let choice = getRandomComputerChoice(question.choices);
let result = getResults(question, choice);



Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15

Challenge Information:

Build a Quiz Game - Build a Quiz Game

let question = getRandomQuestion(questions);
let choice = getRandomComputerChoice(question.choices);
let result = getResults(question, choice);
console.log("Result:", result)

question = getRandomQuestion(questions);
choice = getRandomComputerChoice(question.choices);
result = getResults(question, choice);
console.log("Result:", result)

question = getRandomQuestion(questions);
choice = getRandomComputerChoice(question.choices);
result = getResults(question, choice);
console.log("Result:", result)

check what your function is returing. Does it always return something? or do you see somethign that is not one of the two requested strings?

..i forgot to add the return on the else clause of the Results function. thanks

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