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 trialYemaya Re
Courses Plus Student 1,922 PointsWhat am I missing/doing wrong with this challenge?!
This is the challenge:
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( ) method.
This is the error msg:
Bummer! You need to log out EVERY number from 4 to 156 to the console. Your loop calls the console.log() method 1 times.
I ran the code in the text editor and it logs every number to the console as instructed. Am I supposed to call the console log method multiple times? I'm unsure how. Every time I tweak it, I get it MORE wrong. Please assist. Thank you very much for any help!
var loop = '';
for ( var i = 3; i <= 156; i += 1 ) {
loop += i + ' ';
}
console.log(loop);
2 Answers
Steven Parker
231,275 PointsThe test "i !== 156
" will cause the loop to stop before 156, but the instructions wanted that value included. Your original test of "i <= 156
" would be better.
Also, you don't need to append a space to the number when you log it.
Steven Parker
231,275 PointsYou can log each number by calling "console.log" inside the loop. That will also save you from needing the string variable.
But you may have another issue also since the instructions say to start at 4 but your loop index starts with 3.
Yemaya Re
Courses Plus Student 1,922 PointsHey, thanks for your time! I've changed it to this:
for ( var i = 4; i !== 156; i += 1 ) { console.log(i + ' '); }
And it gives me this error: Bummer! You need to log out EVERY number from 4 to 156 to the console. Your loop calls the console.log() method 152 times.
I have tried so many things that I think SHOULD be correct and NOTHING is working...I'm confused what more needs to be done.
Yemaya Re
Courses Plus Student 1,922 PointsYemaya Re
Courses Plus Student 1,922 PointsI didn't know either of those things. Thanks!
Yemaya Re
Courses Plus Student 1,922 PointsYemaya Re
Courses Plus Student 1,922 PointsJust seeing this response! Thanks so much!