Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.