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 1 Solution

Norma Ikeda
Norma Ikeda
1,242 Points

Why does its necessary to define the value 0, for var correctAnswer works?

I don't get why its not necessary to give a value to all the variables, except for correctAnswer.

var correctAnswer = 0;
var question;
var answer;
var response;
var html;

Thank you very much for your help! ^^

Edit: Made the javascript more readable. - Dane E. Parchment Jr. (Moderator)

1 Answer

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

The reason the correctAnswers variable is initiated with a 0 is because he has to increment the number in a loop, so he starts the variable off at 0 for easier incrementing.

Norma Ikeda
Norma Ikeda
1,242 Points

Dear Dane, thank you very much for your help!