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

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

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