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

correct +=

I understand most of the code but I am getting confused with the concept of correct + 1= on the challenge solution video. I know it is an abbreviation of correct = correct + 1. Any insight would be really appreciated!

1 Answer

Steven Parker
Steven Parker
231,275 Points

You didn't get the syntax quite right, it's "correct += 1".

But you're right, it does the same thing as "correct = correct + 1".

thanks! I have another syntax question. are the following two statements the same?. thanks

var correct = correct + 1

 correct =  correct + 1
Steven Parker
Steven Parker
231,275 Points

The "var" version is improper syntax. It's declaring "correct" as a new variable but trying to access its value at the same time.

The other one is legitimate providing that "correct" was previously declared and assigned.

thanks. Sorry, I am trying to understand this concept: Are the following statements equal.

var correct = 1;

correct = 1;

Steven Parker
Steven Parker
231,275 Points

The statement "var correct = 1;" declares the new variable "correct" and assigns the value 1 to it at the same time. A variable should only be declared once, so "correct" should not exist previous to this statement.

Just "correct = 1;" assigns the value 1 to the variable. This can be done anytime, and repeatedly as desired, to an existing variable. If "correct" does not already exist and the system is not in "strict" mode, it will be created in the global scope. But in "strict" mode implicit global declarations are not allowed and an error will occur.

thanks for the last answer. Now it makes sense. thanks. have a great weekend

Steven Parker
Steven Parker
231,275 Points

Geovani Mejia — Glad to help. You can mark a question solved by choosing a "bet answer"
And happy coding!.