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 trialSteve Tenpas
6,234 PointsDoes 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.
for ( var i; 3 < i < 157; i+=1 ){
console.log(i);
}
3 Answers
Simon Coates
28,694 Pointsyou just need to assign the loop variable directly to 4.
for ( var i = 4; i < 157; i+=1 ){
console.log(i);
}
Shadi Abdelsalam
9,490 PointsIf 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
9,490 PointsYou will get an 'undifined' appered in you console.
Steve Tenpas
6,234 PointsGot it. Thanks
Steve Tenpas
6,234 PointsSteve Tenpas
6,234 PointsThank you.