Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.