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 trialgregory gordon
Full Stack JavaScript Techdegree Student 14,652 PointsCreate a for loop that logs the numbers 4 to 156 to the console. To log a value to the console use the console.log( ) me
can not complete challenge.
var html = ' ';
for ( var i = 4; i <= 159; i += 1 ) {
html += ' ' + i + ' '; console.log(html);
}
2 Answers
Marcus Parsons
15,719 PointsHey Gregory,
It looks like you have a lot going on in your code that is unnecessary. You don't need to initialize any other variable besides the one you use directly inside the for loop. Also, since the challenge wants from 4 to 156, you need the condition to check when i is one below the max number you want. In this case, we want i < 157 because when it gets above 156, the for loop will stop executing. And then you only need to use console.log with i. There's no need for any other variables.
for (var i = 4; i < 157; i += 1) {
console.log(i);
}
Moises Miguel
5,028 PointsHI gregory, can you tell me how you solved this please?
gregory gordon
Full Stack JavaScript Techdegree Student 14,652 Pointsgregory gordon
Full Stack JavaScript Techdegree Student 14,652 PointsOnce i posted this i realized what i did wrong i changed my code and it worked but i will still give you best answer credit since it is the correct answer. Thanks for helping out the community.
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsMy pleasure, Gregory! Happy Coding!
Brandon Miller
6,818 PointsBrandon Miller
6,818 Pointsthe <= 157 should be < 157, eh?.... not sure why I thought it needed an equals sign to be true.