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 trialgaby ibarlucea
4,213 Pointswhy 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?
5 Answers
Tamas Gonda
7,332 PointsHe 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>
Joseph Boyd
1,286 PointsI have to say tats not a good answer. i mean why use <p> </p> and not just a ('')?
Loris Guerra
17,536 PointsThat'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.
Dylan Davenport
Courses Plus Student 2,645 PointsMy question is why do we need the . before the closing paragraph tag??
Tom Oesterman
Courses Plus Student 8,889 PointsYou 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.
Curtis Simonson
UX Design Techdegree Graduate 13,791 PointsIt also determines the size of the message that is returned. Try an <h1></h1> instead to see the difference.
luckychukwuladimasi
Courses Plus Student 2,282 Pointsluckychukwuladimasi
Courses Plus Student 2,282 PointsThank you for the question.., I thought I was the only one wondering why the paragraph tag.