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 trialAllison Guthrie
6,781 PointsStuck in a for loop
Hmmm...can someone smarter than me please help me out? I feel like my error is a dumb one, but I can't seem to figure it out. I am trying to create a 'for' loop that logs the number 4 - 56 in a console.log method. In advance, thank you!
2 Answers
Donald Brunais
8,895 PointsA for loop has 3 parts initialization, condition and final-expression. your var i = 4 is is the initialization. You condition is wrong. You needs something that going to go to true or false. so i < 100 is an example. Your final expression runs ever time the loop runs. So if you want to go from 4 to 100 you would do i++. Here is what that looks like
for(var i = 4; i < 100; i++) {
console.log(i);
}
Aaron HARPT
19,845 PointsHere is the code that worked for me: for (var i = 4; i < 157; i = i + 1) { console.log(i); }
Allison Guthrie
6,781 PointsThank you! I so appreciate this!
Allison Guthrie
6,781 PointsAllison Guthrie
6,781 Pointsthank you so much for answering...makes sense. i appreciate your time!