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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Useful Array Methods

Kevin Alvarez
Kevin Alvarez
4,851 Points

Paragraph tags in Javascript

Why is necessary to use paragraph tags in his print function? Why not just use the document.write( ) method with string quotation marks instead of using the tags, when you need to print something on to the page?

4 Answers

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

The paragraph starts a new line. Just printing spaces doesn't.

Hi, I believe the answer is...it's NOT necessary. As far as the p tags vs no tags: The p tags or li tags will come with certain styles that may help the look of what's being printed. Without any tags, a line of text may just run on. A p tag will break the line up and add some padding or margin (I forget which). An li tag will break the line up, maybe add a bullet but I think no padding or margin.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

The paragraph tags help add some HTML into your JS scripts. You can then target the output HTML with CSS selectors to display the text how you want.

The paragraph tag in your string will put the text on a new line but you can also do this with the \n escape character.

Kevin Alvarez
Kevin Alvarez
4,851 Points

Alright i get it now, thanks for the help everybody.