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 trialDana Holdt
5,578 PointsNeed help with challenge: Creating a 'for' loop that prints 4 - 156?
I am a bit confused as to how this isn't functioning properly. If I change the start number to '3' the individual numbers between 3 to 156 are printed to the log and the challenge yells at me saying the printed numbers must be between 4 and 156. However, if I change the starting number to '4' I get an error stating 'The console.log needs to print the individual numbers from 4 to 156 to complete the loop'.
var num = ' ';
for ( var i = 4 ; i <= 156; i += 1){
num = i + ' ';
console.log (num);
}
2 Answers
Karolin Rafalski
11,368 PointsYou are adding a space to each number. The challenge only wants you to print the number.
for (var i = 4; i <=156; i++){
console.log(i);
}
Pavithra Manivannan
7,474 PointsYou put a space between console.log and the argument num. try this. var num = ' ';
for ( var i = 4 ; i <= 156; i += 1){ num = i + ' '; console.log(num); }
Dana Holdt
5,578 PointsDana Holdt
5,578 PointsAhhh... Thanks, I'll try that. One quick question about your answer: The ' i++ ' ? I haven't encountered that before? I'm going to guess it's another useful shorthand?
Karolin Rafalski
11,368 PointsKarolin Rafalski
11,368 PointsYeah, you've got it. :-)