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 trialJeremiah Walker
2,953 Pointscreate a for loop challenge
Please help, i'm confused.. the question is asking me to create a for loop that prints out all the numbers from 4 to 156 to the console. This is my code below. Thanks!
for ( var i = 4; i < 156; i++ ) { console.log(); }
for ( var i = 4; i < 156; i++ ) {
console.log(152);
}
3 Answers
Stephen Layton
8,643 PointsYour console.log
is writing 152.
for ( var i = 4; i < 156; i++ ) {
console.log(152);
}
It should be writing the variable i that contains the count.
for ( var i = 4; i < 156; i++ ) {
console.log(i);
}
As its currently written it will only write up to 155 so you'll need to adjust your for loop to account for that.
Chyno Deluxe
16,936 PointsThe variable i is what will generate the numbers between four and 156. So you will need to change the < to <= to include 156 as well and console log the i. Vew below
for ( var i = 4; i <= 156; i++ ) {
console.log(i);
}
I hope this helps.
Jeremiah Walker
2,953 PointsThanks Chyno! Had to change it from 152 to 157
Chyno Deluxe
16,936 PointsThat works as well haha. That's the beauty of JavaScript. There are so many ways to get the same results.
Jeremiah Walker
2,953 PointsJeremiah Walker
2,953 PointsThanks Stephen it worked!