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!

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 Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge

challenge questions

I have two silly questions: 1) what does +1 or ++ do exactly 2)why does var = correctAnswers equal zero?

1 Answer

Steven Parker
Steven Parker
227,114 Points

Well, "+1" is just "and one more", but I'm thinking you might have meant "+= 1" using the addition assignment operator which means "increment by one". Now "++" is the increment operator, which will also increment something by one, but it comes in two "flavors" depending on which side of the operand you put it. If you're using these as complete staements, all 3 do the same thing. But in expressions, the post-increment operator (when you put "++" after the operand) has the value of the operand before it is incremented. You probably won't use that in any beginner exercises.

I'm not sure I understand question 2. I would expect "var = correctAnswers" to be a syntax error, since "var" is a keyword used to create variables and there's no variable name between it and the equal sign. Even if that's not what you meant to write, I'd probably need to see a lot more of the code to determine why something was getting a value of zero.

For future questions, remember to use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down: Or watch this video on code formatting.

I meant to write var correctAnswers = 0. Either way, thank you so much for answering!

Steven Parker
Steven Parker
227,114 Points

In that case, it's easy, "=" is the assignment operator, it gives the value of whatever is on the right to whatever is on the left. So in this case, the variable correctAnswers is being created and at the same time it is given the value 0 (zero).