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

Randell Purington
Randell Purington
9,992 Points

I could use some help

You need to log out EVERY number from 4 to 156 to the console. Your loop calls the console.log() method 1 times. That is the error I am getting.

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

1 Answer

Mike Hickman
Mike Hickman
19,817 Points

Hi Randell,

You're super close. You just need to remember that you want to put the actions that you want performed during the for loop, actually within the loop.

If you move the console.log line up into the for loop, it will run perfectly.

for (var i = 4; i <=156; i += 1) {
  // guess what goes on this line? ;)
}

Also, you'll probably learn this shortly, but instead of i += 1, which means "add 1 to whatever i is each time we loop", you can use the shorter i++, which does the same thing.

Cheers, Mike

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

Hi Mike,

I just wanted to let you know I edited your answer so the code has syntax highlighting. You can do this by adding the name of the language in the code block after the first set of back-ticks.

Happing Coding!