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

for (var i = 4; i <= 156; i++) { console.log([i]); } I dont know

for (var i = 4; i <= 156; i++) 
{
  console.log([i]); 
}

Its all true, why it dont let me pass?

2 Answers

for (var i = 4; i <=156; i++)
{
  console.log(i); 
} 

Your for loop is not true. The square brackets aren't used for calling out the single variable.

//Changed Comment to Answer

Listen nipi u have messed the for loop's theory up The correct code is this

for (var i = 4; i <= 156; i++) 
{
  console.log(i); 
}

U dont put 'i' inside of square brackets when u are just logging the number out to the console or when u are printing stuff directly to the document using document.write

U ONLY put [i] when u are dealing with arrays Lets say u have an array called 'colors'..inside that array u have 5 array items. If you want to loop through these array items u can do it with a for loop like this.....

for(var i = 0; i < colors.length; i++){
   console.log(colors[i]);
}

Remember...u only use the counter with square brackets like this '[i]' only when looping through arrays Mark my answer as the best if i managed to help u