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 trialWilliam Coshburn
6,125 PointsWhy is <p> in quoates? <p> "<p>" + randomNumber + " is a number between 1 and " + topNumber + ".</p>";
Why did we put the html tag <p> in quoates on line 4?
"<p>" + randomNumber + " is a number between 1 and " + topNumber + ".</p>";
Maybe I'm over thinking things but I'm trying to understand each step. Thanks!
1 Answer
Emmanuel C
10,636 PointsBecause itll turn that entire statement into a one big string. Then when he uses document.write(), he'll insert that string as it was a html tag. If random number was 5 and top number is 10. The string would look like
var message = "<p>5 is a number between 1 and 10.</p> ";
Which is a valid html statement, then the javascript will write that to the document, as if you manually wrote that to the html document. I hope that made sense.
William Coshburn
6,125 PointsWilliam Coshburn
6,125 PointsOh so that's why without the <p> nothing shows. I figured without the p the line would still print. That part I didn't get.
Ariana Kautz
Full Stack JavaScript Techdegree Student 1,657 PointsAriana Kautz
Full Stack JavaScript Techdegree Student 1,657 PointsSo every time if you write a message like this you will need a <p> tag?
Emmanuel C
10,636 PointsEmmanuel C
10,636 PointsIts doesnt have to be a <p>, It could be any element. The document.write() function simply writes any string to the document, as if you typed it into the html. So the string should be a valid html statement.