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

# Why isn't my code working?

my code is not working

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

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

do {
guess = prompt('I am thinking of a number between 1 and 10. What is it?');
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);
```

STAFF

Hi there! Your code is just fine! So the question becomes why it works for me and not for you. Here are some things to check:

• make sure you saved your JavaScript file

Hope this helps!

Jennifer is right.....upvoted.

You never added the curly braces for the while loop.

```do {
guess = prompt('I am thinking of a number between 1 and 10. What is it?');
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);
}
```

Elijah Quesada The student who posted the question has a functional `do while` loop. Your code will produce an infinite loop which hangs the browser as it contains no code to set the `correctGuess` to true. Take a look at the code in the question again Thanks for helping out in the Community!

Sorry, maybe I misunderstood what you meant. I thought, originally, that you meant to remove the `do` part and just have the while part. If that is not what you meant, then it would not be an infinite loop, but adding the curly braces will have no effect