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 trialIosif Skorohodov
1,126 PointsWhat is the ++ all about?
I only got this correct because I had to Google search for the answer.
for (var num = 4; num <= 156; num++){
console.log(num);
}
How is this the correct answer? What does the ++ all about?
This was my code:
for (var num = 4; num = 156){
console.log(num);
}
1 Answer
justdave
31,518 Pointsokay. the ++ is a shorthand method. The long method would be num = num +1;
. Each time you run thorough the for loop you take the existing value for num, and add 1 to it. It's so common that we use num++
instead of the full statement. There are a few other shorthands that do basically the same and you may come across and look up as you encounter them, but for now just know it's the shorthand for getting the current value then adding 1 to it. Hope that helps!
In your code their you are setting, the start value, the end value, but are missing the increment value, which is what you need to count through the number of loops.