Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 2 Solution

Kirby Abogaa
Kirby Abogaa
3,058 Points

Object/Variable Question

Does the below code push/create an object 'correct' and 'wrong' into the variable 'question' ?

var question;

if (response === answer) {
    correctAnswers += 1;
    correct.push(question);
  } else{
    wrong.push(question);
  }

1 Answer

Grace Kelly
Grace Kelly
33,990 Points

Hi Kirby, you've got the right idea except there are a couple of issues, the push() function adds a value to the end of an array, so in order to "push" the value we need to create an array to put the value into, like so:

var correct = []; //this creates an empty array

What you are asking in your conditional statement is whether or not the user's response is the correct answer. If you want to keep track of the questions answered correctly, you push the question into the correct array, like so:

 if (response === answer) {
    correct.push(question); //this pushes the question into the correct array
  } 

This adds the question into the correct array, it doesn't create a "correct" object in the question variable

Hope that helps!!