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

Helen King
Helen King
9,717 Points

Create a for loop that logs the numbers 4 to 156 to the console. To log a value to the console use the console.log( ) me

I'm struggling with these loops, I have a general idea of what needs to be written but don't know how to write it!

this is what I have so far....

script.js
var number = '';
for (var i = 4; i< 157; i += 1) {

}
console.log(i); 

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Oh if you only knew how close you are! First off you don't need the number variable as your "i" variable is all that's needed here. Then if you just place the console.log in your code block... voilá! Here... see what I mean:

for (var i = 4; i< 157; i += 1) {
   console.log(i);
}
Helen King
Helen King
9,717 Points

ah i have my console log in the wrong place! thank you Jennifer :)