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 trialdjsands
6,286 Pointsso what is the difference between theses 2 .. . .
So I was going over some of the exercises and I went onto the for loop and I was doing this ...
var html = '';
for (var i = 1; i <= 10; i += 1) { html += '<div>' + i + '<div>'; } document.write(html);
and this left me with the number circles going across the browser diagonally but then when I searched questions and pasted a copy of a suggestion, which to my eye looks exactly the same -- it worked correctly ... ??
var html = ''; for (var i = 1; i <= 10; i += 1) { html += '<div>' + i + '</div>'; } document.write(html);
I must have been staring at it for too long because I cant see any difference but one runs correctly and the other doesn't . .. .
2 Answers
Steven Parker
231,153 PointsThe first example has a tag error:
html += '<div>' + i + '<div>'; <!-- first example has two start tags (error) -->
html += '<div>' + i + '</div>'; <!-- second example has start and end tags (correct) -->
Mei Lee
3,339 PointsThe first one has <div> instead of </div> for the closing tag.
djsands
6,286 Pointsdjsands
6,286 PointsOK , I just saw .. . .
html += '<div>' + i + '<div>';
and
html += '<div>' + i + '</div>';
I should really walk away after staring for too long . .. . . LOL