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) Working With Numbers The Random Challenge Solution

why does he put <p> </p> in quotation marks?

in the video, he wrote

var message = "<p>" + topNumber + otherStuff + ".</p>"

What is the purpose of the paragraph tags in quotation marks? Is it necessary? If so, why?

Thank you for the question.., I thought I was the only one wondering why the paragraph tag.

5 Answers

He writes it that way because topNumber and otherStuff are variables, not strings. You could write <h1> or whatever instead. The thing is as long as it's a string, should be surrounded with commas. Just another example. document.write("<h1>Hello my Dear friend! I hope everything is OK!</h1>"); or document.write("<h1>Hello my Dear friend! I hope everything is " + exampleVariable + "</h1>

I have to say tats not a good answer. i mean why use <p> </p> and not just a ('')?

That's because the "document.write()" method expects a string as augument in order to render something to the browser. For this reason you need to wrap your HTML code using quotes.

My question is why do we need the . before the closing paragraph tag??

You do not need the period before the closing paragraph tag. The instructor included the period to end the displayed sentence. It has nothing to do with the code.

It also determines the size of the message that is returned. Try an <h1></h1> instead to see the difference.