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 loop

Each time i run this code ,i get a message that "your code took too long to run" , i am not sure what i'm doing wrong. Should there be any thing in the set of braces?

script.js
for(var i = 1; 4<i<156; i+=1){


}
document.write(i);
eslam said
eslam said
Courses Plus Student 6,734 Points

your code should look like this :

for ( var i=4 ; i<157 ; i++ ) {
document.write(i);
}

and if you want to add every number in a separate line use this :

document.write(i + "<br>");

1 Answer

Hi Matthew, yes there should be something in the pair of curly braces and that is the console.log() statement. The conditions you used to construct your 'for' loop is what is making it take too long to run. Here's a more concise way:

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

Here you start at the value of 4 and iterate through as the number increases by 1 each time the loop runs until the number is equal to 156. Any number above 156, the loop stops running.