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!

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

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
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

You don't need a while loop for this since there is no condition being met.

for (var i = 4; i < 157; i += 1) {
Brian Foley
Brian Foley
8,440 Points


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