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 Simplify Repetitive Tasks with Loops `do ... while` Loops

How come at the last part of Dave's code his Document.write doesn't have a h1 tag name inside it.

His document.write() didn't have any tag name. I copied it and it didn't follow. On the other hand, his code worked by doing the same exact. Here's my code:

var randomNumber = getRandomNumber(10); var guess; var guessCount = 0; var gg = false;

function getRandomNumber( upper ) { var num = Math.floor(Math.random() * upper) + 1; return num; }

do { guess = prompt("I'm thinking of a number between 1 and 10. What is it?") guessCount++; if(parseInt(guess) === randomNumber) { gg = true; } } while(! gg)

document.write("<h1> You guessed the correct number! </h1>") document.write("It took you " + guessCount + " tries to guess the number " + randomNumber )

//nothing was applied to html

2 Answers

Steven Parker
Steven Parker
231,269 Points

Nothing appears on the page until the correct number is guessed.

But that's just how the program is written.

And the second document.write doesn't have a tag because it's only writing plain text to the document, not a header. Text in an HTML document doesn't always need to be in a tag.

Did that cover your question?

yes thx

I found the answer by accidently putting an "a" in my html no help needed