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 trialVardas Pavarde
641 PointsCreate a for loop that logs the numbers 4 to 156 to the console. To log a value to the console use the console.log( )
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.
8 Answers
sizwengubane
15,244 PointsIn this case, you have to create a counter variable called 'i' inside the loop and set its starting value to 4, then u have to create a condition saying 'i <= 156', next you need to increment the value stored inside i by one each time the loop runs.
for( var i = 4; i <= 156; i++){
console.log(i);
}
Mark my answer as the best if i managed to help u
Solomon Ray
4,021 PointsHey Guys!
this is how i did it:
for ( var i = 4 ; i <= 156; i += 1 ) { console.log( i ); }
Amar Mohammed
6,795 PointsThat worked, thank you!!!
karson Adam
32,623 Pointsyou need to create for loop and start with initial value i = 4 and stop when i is 156 ,and print i each time
for ( i = 4 ; i< 157; i++){
console.log(i);
}
KARMA DRUKPA
7,235 Pointsfor (let i = 4; i <157; i++){
console.log(i);
}
I Don't know why this code is not working, it should definitely work as of my best knowledge. TreeHouse is not marking as right answer.
``
Kamal Ghimire
12,143 Pointsfor ( let i = 5 ; i <= 100; i++ ) { console.log( i ); }
This can solve your problem. It shows that there should be an increment of (i) up to 100 times. I tried on the console of chrome developer tools.
Nasheed Rashad
11,243 Pointsthis is the only one that worked for me - thank you!
kathyvuong
9,299 PointsTry this, for ( var i = 4; i <= 156; i += 1; ) { console.log(i); }
kathyvuong
9,299 PointsThis is a correct answer. You can try it.
for ( var i = 4; i <= 156; i += 1; ) { console.log(i); }
Richard Wong
Full Stack JavaScript Techdegree Student 1,888 PointsAhhhh I left out the 'var' part in the first part of the for loop