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
Raphael Hetherington
Courses Plus Student 1,622 PointsStuck on the first 'for' loop challenge!
Hi guys,
I'm not sure where I'm going wrong and getting a parse error. I have to write a for loop that will print the numbers 4 to 156 in the console. Here's what I wrote:
var i = 0; for (i = 4; i <= 156; i += 1;) { console.log(i); }
I'm not getting anything...can anyone help?
Thanks!
2 Answers
Julian Gutierrez
19,325 PointsThere is no need to declare "i" outside of the loop, the first part of a for loop takes care of that for you. Just include "var" when declaring "i" in your for loop.
for(var i = 4; i<=156; i++){
console.log(i);
}
Raphael Hetherington
Courses Plus Student 1,622 PointsThanks so much! I think one of the main problems was the semicolon after the third statement in the 'for' bit. Thanks again though!