Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

I don’know how to solve the tests 7, 11, 12 and 13

Your code so far

const questions = [
  {
    category : "Food",
    question : "Do you like tomatoes?",
    choices : ["Yes", "No", "It is irrelevant."],
    answer : "Yes"
       
  },

  {
    category : "Food",
    question : "Do you like tomatoes?",
    choices : ["Yes", "No", "It is irrelevant."],
    answer : "No"
  },

  {
    category : "Clothes",
    question : "Do you like dresses?",
    choices : ["Yes", "No", "It is irrelevant."],
    answer : "It's irrelevant"     
  },

  {
    category : "Travel",
    question : "Do you like travel?",
    choices : ["Yes", "No", "It is irrelevant."],
    answer : "No"       
  },

  {
    category : "Games",
    question : "Do you like travel?",
    choices : ["Yes", "No", "It is irrelevant."],
    answer : "No"  
  }
];


function getRandomQuestion(question) {
  const index = question.length;
  const randomIndex = Math.floor(Math.random()*index);
  return question[randomIndex];
}

console.log(getRandomQuestion(questions).answer);

function getRandomComputerChoice(questionChoices){
    const index = questionChoices.length;
    const randomIndexChoice = Math.floor(Math.random()*index);
  return questionChoices[randomIndexChoice];
}

console.log(getRandomComputerChoice(questions).answer);

function getResults(answer, computerAnswer) {
  //const questionAnswer = getRandomQuestion(question).answer;
  //const computerAnswer = getRandomComputerChoice(question).answer;
  if( answer === computerAnswer){
    return "The computer's choice is correct!";
  } else {
    return "The computer's choice is wrong. The correct answer is: " + answer;
  }

}

console.log(getResults(getRandomQuestion(questions).answer,getRandomComputerChoice(questions).answer));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:138.0) Gecko/20100101 Firefox/138.0

Challenge Information:

Build a Quiz Game - Build a Quiz Game

What are tests 7, 11, 12 and 13?

Can you say what parts of your code you think should satisfy those tests and what debugging you’ve tried?

For example:
// tests completed
// console output
No
No
The computer’s choice is correct!

No
Yes
The computer’s choice is wrong. The correct answer is: It’s irrelevant

Please answer all of my questions.

Sorry,
I don’t know how to answer, “it’s irrelevant” isn’t written, I changed it to “it is irrelevant.” I’ve reset several times and it continues.

And at first it worked and I only had test 7 left.

You could answer by first saying what tests 7, 11, 12 and 13 are:

You would then next say what code you have written you think satisfies those requirements.

  1. The value of answer should be included in the choices array.

Why did you only answer part of one of the two questions?

Please answer those two questions above. Pretty please

I don`t know how to respond, but no problem.
Sorry for wasting your time. I’ll figure it out later with more JavaScript experience.

You figured out how to say what test 7 is. I am not sure why it is difficult for you to say what tests 11, 12, and 13 are? I am genuinely confused.


Can you say what about this you do not understand?

Test 1 says

You should create an array named questions.

The part of your code that is for that test is this part:

What are the parts of your code that you think do what tests 11, 12, and 13 ask for?

Hi there,

Please focus on this bit of the 9th user story:

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.

Your call to getRandomComputerChoice() is not correct. Wouldn’t you need to get the question object first so you can get that specific question’s choices to pass to getRandomComputerChoice()? What variables could you create then to use in your call to getResults()?

Well, 'm continuing to work on this project. For now, what I’ve managed to do, and this is amazing, is understand what I’m doing.
But I don’t understand :

step 7: The value of answer should be included in the choices array.

My code is the next:

const questions = [
  {
    category : "Food",
    question : "What fruit do you prefer?",
    choices : ["tomatoes", "bananas","apples"],
    answer : "bananas"
       
  },

  {
    category : "Food",
    question : "Do you like tomatoes?",
    choices : ["Yes", "No", "It's irrelevant."],
    answer : "No"
  },

  {
    category : "Clothes",
    question : "Do you like dresses?",
    choices : ["Yes", "No", "It's irrelevant."],
    answer : "It's irrelevant"     
  },

  {
    category : "Travel",
    question : "Do you like travel?",
    choices : ["Yes", "No", "It's irrelevant."],
    answer : "No"       
  },

  {
    category : "Games",
    question : "Do you like travel?",
    choices : ["Yes", "No", "It's irrelevant."],
    answer : "Yes"  
  }
];
//	Access to the properties of an object 
console.log(questions[2].choices); // object => Yes,No,It's irrelevant. 
console.log(questions[2].choices[0]); // string => Yes
console.log(questions[2].answer + "\n\n"); // string => It's irrelevant.

//The function randomly chooses an element from the array.
function getRandomQuestion(questions){
	const index = questions.length;
        const randomIndex = Math.floor(Math.random()*index);
  
       return questions[randomIndex];
}

console.log(getRandomQuestion(questions)); //[object Object]

/*	{ 
category: 'Food',
 question: 'Do you like tomatoes?',
choices: [ 'Yes', 'No', 'It\'s irrelevant.' ],
answer: 'No'
}
*/


//	Now, getRandomQuestion(questions).choices | output => array | ["Yes", "No", "It's irrelevant."]

/*	The next function takes the array, choices, of the available choices as a parameter, and returns a random answer to the selected question.*/

function getRandomComputerChoice(questionChoices){
  const index = questionChoices.length;
  const randomIndex =  Math.floor(Math.random()*index);
  return questionChoices[randomIndex];
}

// the question object:
const randomChooseArrayItem = getRandomQuestion(questions);

// then, the computer's choice:
const randomComputerChoice = getRandomComputerChoice(randomChooseArrayItem.choices);

console.log("\n\n" + getRandomComputerChoice(randomChooseArrayItem.choices) + "\n\n"); //string | tomatoes

/* The next function takes the question object, as the first parameter and the computer's choice as the second parameter. */

function getResults(randomChooseArrayItem, randomComputerChoice){

  if(randomChooseArrayItem.answer == randomComputerChoice){
    return "The computer's choice is correct!";
  } else {
    return "The computer's choice is wrong. The correct answer is: " + randomChooseArrayItem.answer;    
  }
}

console.log(getResults(randomChooseArrayItem, randomComputerChoice));

It just means that when you create your questions array of question objects, that the value of the answer property in each question object should be included as one of the array elements in the choices property, which you have done.

Thanks, then, why the project did not pass?

/ running tests
7. The value of answer should be included in the choices array.
// tests completed
// console output
[ 'Yes', 'No', 'It\'s irrelevant.' ]
Yes
It's irrelevant


{ category: 'Food',
  question: 'What fruit do you prefer?',
  choices: [ 'tomatoes', 'bananas', 'apples' ],
  answer: 'bananas' }


apples


The computer's choice is correct!

I think that the project dosen`t work very well..

the dot/period/full stop is a character, if one string has it and the other doesn’t they are different strings, double check your third object

1 Like

Thanks a lot!!!
Almost two months to understand, and today a tiny bit. The ratio is right. :grinning_face:
You are awesome!

1 Like