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 trialBrenna French
1,357 PointsWhat am I doing wrong?
need an example
for (var i = 4, i <= 156, i += 1){
}
console.log(i);
2 Answers
Evgeniia Mas
4,452 PointsHello! Syntax mistakes: in condition semicolons (not two commas), console.log move between { }, not outside.
Like this: for (i = 0; i < cars.length; i++) { text += cars[i] + "<br>"; }
Jason Anders
Treehouse Moderator 145,860 PointsHey Brenna,
You're on the right track, there is just a bit of a syntax error, and the console.log
is outside of the loop.
First, inside the for loop
, the statements need to be separated with semi-colons, not commas.
Next, you want the console
to log the number after every loop. If you place it outside of the curly braces, the loop will still run through all the numbers, but it will only log the last number. This is because code outside of the block won't execute until the loop finishes. So, you need to move the console.log
inside of the loop so that is runs with every iteration of the loop.
for (var i = 4; i <= 156; i += 1){
console.log(i);
}
Hope that helps.
Keep Coding! :)