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 JavaScript Basics (Retired) Storing and Tracking Information with Variables The Variable Challenge Solution

Andrew Denson
Andrew Denson
4,544 Points

This code works without closing tag for <h2> element?

var adjective = prompt('please type an adjective'); var sentence = "<h2> there once was a " + adjective; document.write(sentence);

Why does this work without the closing tag for the <h2>. If the code didn't have any html elements to the text would be really small. I know by putting the document.write to it this clarifies that it is html markup. I am not understand why you don't need a closing tag to complete it.

1 Answer

Niclas Hilmersson
Niclas Hilmersson
8,296 Points

In normal HTML you can use tags without an ending tag and that will work just fine. BUT it's not recommended since that could cause confusion and some errors and bugs in the end.