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

What am I doing wrong here?

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

1 Answer

John Clune
PLUS
John Clune
Courses Plus Student 4,951 Points
for (var number = 4; number <= 156; number++){
console.log(number);
}

You need to log numbers 4 - 156 to the console. As in 4, 5, 6, 7, 8 .... 156. So you start by saying for, then inside the brackets you declare and initialize a variable with a value of 4 (in this case I called it number so it's easier to understand). The second part checks if the number is less than or equal to 156 (as long as that is true the loop will keep running), and the third part increases the number by 1 every time the loop runs. The last thing is to put the log to the console inside the loop so that it prints out the value of number every time the loop runs. Hope that makes sense.

Shuu! you are brilliant, i will realy need your help with Js, i cant make it alone.