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 trialJames Barshaw
9,284 Pointshow to create a for loop
I need to understand better how to do this
Create a for loop that logs the numbers 4 to 156 to the console. To log a value to the console use the console.log( ) method. I got this far into make this program and I need help understanding how to do the rest
var counter = 1 for ( var i = 4; i<= 156; i +1 = 1){ counter +=
console.log (counter);
1 Answer
Adam Beer
11,314 PointsChallenge Task 1 of 1
Create a for loop that logs the numbers 4 to 156 to the console. To log a value to the console use the console.log( ) method.
Create a for loop: var i = 4 (from now on), i <= 156 (so far), i ++ (this can be: i += 1 or i += 2 or i += 3 etc, but now i += 1 so i ++). Now you saved the value in to the var i. Put the i inside the console.log().
for ( var i = 4; i <= 156; i ++)
console.log(i);
Check this link. Hope this help.