Build a Quiz Game - Build a Quiz Game

Cuéntanos qué está pasando:

I can’t pass step 9, I think it’s because of how I specify the function parameter.

Tu código hasta el momento

const questions = []


let q1 = {
    category: "LaLiga",
    question: "Equipo campeón LaLiga temporada 23/24?",
    choices: ["A. Barcelona", "B. Real Madrid", "C. Atlético"],
    answer: "B. Real Madrid"
  };
let q2 = {
    category: "EPL",
    question: "Equipo campeón EPL temporada 23/24?",
    choices: ["A. Manchester City", "B. Arsenal", "C. Liverpool"],
    answer: "A. Manchester City"
  };

 let q3 = {
    category: "Scudetto",
    question: "Equipo campeón Scudetto temporada 23/24?",
    choices: ["A. Napoli", "B. Juventus", "C. Inter"],
    answer: "C. Inter"
  };
let q4 =  {
    category: "Ligue1",
    question: "Equipo campeón Ligue1 temporada 23/24?",
    choices: ["A. PSG", "B. Lille", "C. Monaco"],
    answer: "A. PSG"
  };
let q5 =  {
    category: "BundesLiga",
    question: "Equipo campeón BundesLiga temporada 23/24?",
    choices: ["A. Bayer Leverkusen", "B. Borussia Dortmund", "C. Bayern München"],
    answer: "A. Bayer Leverkusen"
  };

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


const getRandomQuestion = (questions) => {
  let randomIndex = Math.floor(Math.random() * questions.length);
  return questions[randomIndex];
} 
const randomQuestion = getRandomQuestion(questions);
console.log(randomQuestion.question);


const choices = randomQuestion.choices;
console.log(choices)

function getRandomComputerChoice(choices) {
  return randomQuestion.choices[Math.floor(Math.random() * randomQuestion.choices.length)]
};

const randomAnswer = getRandomComputerChoice(randomQuestion.choices);

const randomChoice = getRandomComputerChoice(choices);console.log(randomChoice);

const getResults = (randomQuestion, randomChoice) => {
  if (randomChoice === 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(randomQuestion, randomChoice);

console.log(result)

Información de tu navegador:

El agente de usuario es: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36

Información del Desafío:

Build a Quiz Game - Build a Quiz Game

He modificado el cuerpo de la función, no estaba aplicando la variable “choices” que había creado justo arriba para usar de parámetro. Mi código ha superado el paso 9.

you are not using the function parameter, you need to select the response from the choices parameter

wrong topic, this is not yours

1 Like

Yeah, sorry about that. Multiple tabs open.

Thanks, that´s worked!!! :clap:t3: