Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

Aunque lo pruebo a través del navegador y me da bien el resultado en consola, aquí me sigue dando fallos y no se muy bien por que (trato de mejorar inglés pero voy lento así que traduzco para saber que hay que hacer).
Los fallos que me da son los siguientes:
8. Usted debe tener una función llamada getRandomQuestion que toma una variedad de preguntas como un parámetro y devuelve un objeto de pregunta aleatorio de la matriz.

9.Usted debe tener una función llamada getRandomComputerChoice que toma la gama de las opciones disponibles como un parámetro, y devuelve una respuesta aleatoria a la pregunta seleccionada.

11.Su función de resultados debe tomar el objeto de la pregunta como el primer parámetro y la elección del ordenador como el segundo parámetro.

  1. Si la elección del ordenador no coincide con la respuesta, getResults debe devolver La elección del ordenador está equivocada. La respuesta correcta es: “correct-respuesta”, donde la respuesta correcta es el valor de la respuesta correcta a la pregunta elegida.

Your code so far

const questions = [{
  category: "matematicas",
  question:" ¿Cuantas lunas tien la tierra1?",
  choices: ["3","2","1"],
  answer: "1",},
{
  category: "matematicas",
  question:" ¿Cuantas lunas tien la tierra2?",
  choices: ["3","2","1"],
  answer: "1",},
{
  category: "matematicas",
  question:" ¿Cuantas lunas tien la tierra3?",
  choices: ["3", "4","1"],
  answer: "1",},
{
  category: "matematicas",
  question:" ¿Cuantas lunas tien la tierra4?",
  choices: ["3","2","1"],
  answer: "1",},
 {
 	category: "matematicas",
 	question:" ¿Cuantas lunas tiene tierra5?",
 	choices: ["4","2","1"],
 	answer: "1",}
 ];
const numAleatorioQuest = Math.floor(Math.random() * questions.length);
const numAleatorioChoice = Math.floor(Math.random() * 3);

function getRandomQuestion(){return questions[numAleatorioQuest].question;};

function getRandomComputerChoice(){return questions[numAleatorioQuest].choices[numAleatorioChoice];};

function getResults(num){
 const num1 = getRandomComputerChoice();
 const num2 = questions[numAleatorioQuest].answer;
 console.log(getRandomQuestion());
 console.log(num1);
 if (num1 === num2){
  return "The computer's choice is correct!";
  } else if (questions.answer !== num1) {
  return `The computer's choice is wrong. The correct answer is: ${questions[numAleatorioQuest].answer}`
  }
}


console.log(getResults(1));


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0

Challenge Information:

Build a Quiz Game - Build a Quiz Game

you will want to check again what this function should do

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. The function should return The computer's choice is correct! if the answer is correct. Otherwise, it returns The computer's choice is wrong. The correct answer is: <correct-answer>, where <correct-answer> is the value of the correct answer to the chosen question.

1 Like

Después de traducirte, he visto que me escribes , otra vez, el enunciado del fallo pero ya me lo dice el programa, por lo que no me permite avanzar en la solución del fallo, gracias de todas formas.

your function does not take the parameters described in the user story

that takes the question object as the first parameter and the computer’s choice as the second parameter

Sigo sin entenderlo y llevo ya dos días: No consigo ayuda y no quiero pasar por chatgpt por que quiero aprender pero me está constando mucho no hacerlo. Mi frustración va en aumento.

const questions = [{
  category: "matematicas",
  question:" ¿Cuantas lunas tien la tierra1?",
  choices: ["1","2","3"],
  answer: "1",},
{
  category: "matematicas",
  question:" ¿Cuantas lunas tien la tierra2?",
  choices: ["4","5","1"],
  answer: "1",},
{
  category: "matematicas",
  question:" ¿Cuantas lunas tien la tierra3?",
  choices: ["6", "1","7"],
  answer: "1",},
{
  category: "matematicas",
  question:" ¿Cuantas lunas tien la tierra4?",
  choices: ["9","8","1"],
  answer: "1",},
 {
 	category: "matematicas",
 	question:" ¿Cuantas lunas tiene tierra5?",
 	choices: ["10","1","11"],
 	answer: "1",}
 ];

function getRandomQuestion(arr){
  const numAleatorioQuest = Math.floor(Math.random() * questions.length);
  arr = questions[numAleatorioQuest];
  return arr;
  };  
function getRandomComputerChoice(arr){
  arr = getRandomQuestion(questions);
  const array = Math.floor(Math.random() * arr.choices.length);
    return arr.choices[array];};

function getResults(){
let question = getRandomQuestion();
let answer = question.answer;
	console.log(answer);
let indChoice = getRandomComputerChoice();
	console.log(question);
  console.log(indChoice);
  if (answer === indChoice){
  return "The computer's choice is correct!";
  } else if (answer !== indChoice) {
  return `The computer's choice is wrong. The correct answer is: ${answer}`

  }
}
console.log(getResults())

you need to build the functions using the instructions

this is a tricky project if you know English, without understanding English it becomes really really hard

you need to get a random question from the parameter arr, not from the global variable

this function needs to take one of the arrays of choices, for example

and select one of the choices from the array

this one needs to take two parameters, one of the questions objects, and one of the choices from that question

1 Like

Gracias por la ayuda, al traducirte aunque no me quedó claro,he podido encontrar el camino. Pienso que me estaba complicando buscando algo mas automático. :sweat_smile:

const questions = [{
  category: "matematicas",
  question:" ¿Cuantas lunas tien la tierra1?",
  choices: ["1","2","3"],
  answer: "1",},
{
  category: "matematicas",
  question:" ¿Cuantas lunas tien la tierra2?",
  choices: ["4","5","1"],
  answer: "1",},
{
  category: "matematicas",
  question:" ¿Cuantas lunas tien la tierra3?",
  choices: ["6", "1","7"],
  answer: "1",},
{
  category: "matematicas",
  question:" ¿Cuantas lunas tien la tierra4?",
  choices: ["9","8","1"],
  answer: "1",},
 {
 	category: "matematicas",
 	question:" ¿Cuantas lunas tiene tierra5?",
 	choices: ["10","1","11"],
 	answer: "1",}
 ];

function getRandomQuestion(questionsArray){
	const numAleatorio = Math.floor(Math.random() * questionsArray.length);
  return questionsArray[numAleatorio];
  };


function getRandomComputerChoice(choices){
	const numAleatorio = Math.floor(Math.random() * choices.length);

  return choices[numAleatorio];
}



const arr1 = getRandomQuestion(questions);
const arr2 = getRandomComputerChoice(arr1.choices);

function getResults(arr1,arr2){
	if (arr1.answer === arr2){
  return "The computer's choice is correct!";
  } else if (arr1.answer !== arr2) {
  return `The computer's choice is wrong. The correct answer is: ${arr1.answer}`
} else{
	return `Error de lectura`;
}
}
console.log(arr1);
console.log(arr2);

console.log(getResults(arr1,arr2))

you may want to use clearer variable names, none of the two parameters is an array

Pues ya me has liado otra vez, pensaba que definiendo estas constantes , le asignaba variable.

I am suggesting you give better names to variables, those are also not two arrays

but, when a function is defined:

function my_func(a, b) {}

you can give parameters to the function, in this case a and b

a and b gets the value when the function is called
my_func(4, 12) here a has value of 4 and b has value of 12
my_func(10000, 1) here a has value od 10000 and b has value of 1

the variables arr1 and arr2 are not related to the parameters arr1 and arr2

1 Like