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.

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
216,012 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
216,012 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).