Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Kirby Abogaa
3,058 PointsObject/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
33,990 PointsHi 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!!