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 trialGeovani Mejia
Front End Web Development Techdegree Student 7,940 Pointscorrect +=
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
231,268 PointsYou didn't get the syntax quite right, it's "correct += 1
".
But you're right, it does the same thing as "correct = correct + 1
".
Geovani Mejia
Front End Web Development Techdegree Student 7,940 PointsGeovani Mejia
Front End Web Development Techdegree Student 7,940 Pointsthanks! I have another syntax question. are the following two statements the same?. thanks
var correct = correct + 1
correct = correct + 1
Steven Parker
231,268 PointsSteven Parker
231,268 PointsThe "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.
Geovani Mejia
Front End Web Development Techdegree Student 7,940 PointsGeovani Mejia
Front End Web Development Techdegree Student 7,940 Pointsthanks. Sorry, I am trying to understand this concept: Are the following statements equal.
var correct = 1;
correct = 1;
Steven Parker
231,268 PointsSteven Parker
231,268 PointsThe 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.Geovani Mejia
Front End Web Development Techdegree Student 7,940 PointsGeovani Mejia
Front End Web Development Techdegree Student 7,940 Pointsthanks for the last answer. Now it makes sense. thanks. have a great weekend
Steven Parker
231,268 PointsSteven Parker
231,268 PointsGeovani Mejia — Glad to help. You can mark a question solved by choosing a "bet answer"
And happy coding!.