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 trial

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a for Loop

How does this work

Please help

script.js
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
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

You'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);
}

You 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
Brian Foley
8,440 Points

Hello,

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); }