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 PointsCan't move past until I complete challenge. What am I doing wrong/missing??
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!
script.js var loop = '';
for ( var i = 3; i <= 156; i += 1 ) { loop += i + ' '; } console.log(loop);
Someone responded with:
You 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.
I've since changed my code to (it actually works):
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 as to what more needs to be done. Please help, as I can't move on to the next video/quiz until I complete this one challenge. Thanks in advance
1 Answer
Steven Parker
231,275 PointsAs I said in your original question, the 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.
Edgar Spickerman
24,786 PointsEdgar Spickerman
24,786 Pointswell the answer is for(var i=4; i<=156;i++){ console.log(i)} The challenge says to log the number You dont need to format it with the space although it makes it more readable and is technically the same. This loop would include the 4 up to 156. The reason why the second attempt isnt working is because of the space and the loop never includes 156. If you changed the condition to !==157 it would work. However the first answer is generally what you will see as the intent is more clear. Feel free to ask me more ?'s if its still confusing.