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

stage 1 simply repetitive task with loops

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

I tries few diff ways but can't pass.

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

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Ellie,

You've got the syntax nailed down very well, but you want to log EVERY number from 4 to 156. If you look at the challenge it states it has to be inclusive of 4 and 156. The way to do this is with the <= operator which means a condition that is less than AND equal to the condition.

What you're trying to do is count every 4th number.. But to increment you can use either +=1 or ++.

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

Hope this helps :)

thanks!