## 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!

### 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.  # Javascript answer alternative: do while loop

Hi everyone i have a question regarding do while loop for JS. The answer for the teacher for one of his questions was the following.

```var randomNumber = getRandomNumber(10);
var guess;
var guessCount = 0;
var correctGuess = false; //called a flag

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

do {
guess = prompt("Please guess a number");
guessCount += 1;
if (parseInt(guess) === randomNumber) {
correctGuess = true;
}

} while (! correctGuess)

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

'''

While my solution is as follows. The result seems to be the same, or maybe im missing something?

''' Javascript

var randomNumber = getRandomNumber(10);
var guess;
var guessCount = 0;
var correctGuess = false; //called a flag

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

do {
guess = prompt("Please guess a number");
guessCount += 1;

}
while (parseInt(guess) !== randomNumber)

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

'''

Thanks!
```

```const randomNumber = getRandomNumber(10)