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 trialChris Gainz
8,117 PointsWhy won't my for loop work?
The third 'i' doesn't turn blue like the rest, it just stays gray and an error pops up saying parse error
for ( var i = 4, i <= 156, i) {
}
3 Answers
Nikica Maksimovski
Full Stack JavaScript Techdegree Student 14,080 Pointsuse semicolons insead of commas.
for ( var i = 4; i <= 156; i) {
}
Ari Misha
19,323 PointsHiya Christian! Here is the syntax for a "for" loop (just remember this syntax and you'll never get a "for" loop wrong)
for (initialization; boolean expression; steps ) {
//magic happens here
}
If we compare your code with the syntax above, you've got your initialization correct, and boolean expression too. But seems like you're confused with the steps right? Challenge wants you to have steps of "1", consider it default when no steps are given in the challenge. Steps are "how many count you'd like to skip", right?
Here is the code:
for ( var i = 4, i <= 156, i += 1) {
console.log(i);
}
Ernesto Samaniego
4,598 Pointsyou are also forgetting to increment and log (i) to the console.
Chris Gainz
8,117 PointsChris Gainz
8,117 PointsThx