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 trial

JavaScript

Getting weird diagonal divs...

here is my code:

var html = '';

for (var i = 1; i <= 10; i++) {
  html += '<div>' + i + '<div>';
}
document.write(html);

but for some reason the divs are going diagonal. im not sure if theres an error with css but im sure my code is the same as example. too bad i cant screenshot my preview browser to show what's happening. can anyone confirm this is right?

1 Answer

Hi Francis,

Firstly, I have fixed your code formatting so please have a read of Posting Code to the Forum.

The issue with your above code is you have two opening div tags but no closing tag. You simply need to change the second tag so it closes the opening tag and it will stack correctly.

html += '<div>' + i + '</div>';

Happy coding!