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

Does the log to console need to be outside the loop?

Am I able to have the console.log within the loop rather than outside the loop? The example in the lesson uses document.write and places that outside the loop. If I did that I would know what to put within the {}. Any help is appreciated.

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

3 Answers

Simon Coates
Simon Coates
28,694 Points

you just need to assign the loop variable directly to 4.

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

Thank you.

Shadi Abdelsalam
Shadi Abdelsalam
9,490 Points

If you wil put log after the loop,you will get an error.Because you only able to use 'i' variable inside the loop,it is loop's counter.

Shadi Abdelsalam
Shadi Abdelsalam
9,490 Points

You will get an 'undifined' appered in you console.

Got it. Thanks