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 trialVy Nguyen
4,350 PointsHow does this work
Please help
var counter = 4;
while ( counter < 156 ) {
console.log ( counter );
counter += 1;
}
for ( var counter = 4; counter < 156; counter += 1 ) {
console.log( counter );
}
3 Answers
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsYou're asked to create a for-loop and you're actually very close, but you're only logging numbers from 4 to 155.
for (var i = 4; i <= 156; i++) { // by saying i <= 156 you include number 156
console.log(i);
}
Brandon Mahoney
iOS Development with Swift Techdegree Graduate 30,149 PointsYou don't need a while loop for this since there is no condition being met.
for (var i = 4; i < 157; i += 1) {
console.log(i);
}
Brian Foley
8,440 PointsHello,
No need for that while loop in this challenge. For the for loop, most of the time you'll want to shorten it into an "i" like so
for (var i = 4; i <=156; i+=1) { console.log(i); }