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 trialHeather Wood
Courses Plus Student 5,887 PointsCreate a for loop that logs the #s 5 to 100 to the console. Use the console.log() method to log a value to the console.
This was my response: for ( i = 5; i <= 100; i++ ) { console.log(i); }
for ( i = 5; i <= 100; i++ ) {
console.log(i);
}
1 Answer
Steven Parker
231,172 PointsSetting to 0 isn't necessary, you just needed a declaration. It doesn't need a separate line, it can be done as part of the the loop:
for (let i = 5; i <= 100; i++) { // <-- notice the "let"
console.log(i);
}
And even this is only necessary because the challenge operates in "strict" mode. In the default mode your original code would have been fine as is.
Heather Wood
Courses Plus Student 5,887 PointsHeather Wood
Courses Plus Student 5,887 PointsOops! Got it! I forgot to declare the variable to start at zero.
let i = 0;