Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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