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 trialjames mchugh
6,234 PointsI can't get his one
I tried to follow the instructors example and it is telling me syntax error. I really don't understand why.
var html = ' ';
for (var i = 4; i <= 156; i += 1;) {
html += '<div>' + i + '</div>';
}
console.log(html);
1 Answer
Manish Giri
16,266 PointsFirst, you have a syntax error. You don't put the ;
after the last condition in a for loop, so the syntax should be -
for(var i = 0; i < 100; i += 1)
Last, you just need to console.log
the number i
in the loop. You're instead adding a <div>
each time the loop runs, and then logging the result, which is why it won't work.
Just console.log(i);
inside the loop.
james mchugh
6,234 Pointsjames mchugh
6,234 PointsI tried that and get this message. Bummer! You need to log out EVERY number from 4 to 156 to the console. Your loop calls the console.log() method 152 times. This is what I ran. for(var i = 4; i < 156; i += 1) console.log(i);
Manish Giri
16,266 PointsManish Giri
16,266 PointsShow your code then.
james mchugh
6,234 Pointsjames mchugh
6,234 PointsThis is what I ran. for(var i = 4; i < 156; i += 1) console.log(i);
Manish Giri
16,266 PointsManish Giri
16,266 PointsYour loop does not include
156
, which is what you had initially -i <= 156
.james mchugh
6,234 Pointsjames mchugh
6,234 PointsThanks Manish, Yeah that last time I ran it I forgot the = after the <. That worked thank you
Manish Giri
16,266 PointsManish Giri
16,266 PointsWelcome!