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

Why isn't my JavaScript code working? I'm using a while loop...

My code seems to be stuck in an endless loop, can't figure out why. Can you help me?

Here's the snap from treehouse workspaces:

https://w.trhou.se/1lv3slqey9

Thanks in advance!

1 Answer

Hi Jelena Bacic,

What exactly is your error?

I don't know exactly what you were trying to do, but I assume you want the message to remain popping up until they guess the number (I mean because of your while loop, I think that's what you want to do).

If so, great work, it is indeed perfect!

If you want to check and confirm that this works, you just need to do this: after you create and assign randomNumber, make another line that will log its value to the console. Like this:

var randomNumber = getRandomNumber(upperValue, lowerValue);
console.log(randomNumber);

var guessCount = 0;

Then, once you obtained the value, enter it into the dialog box (the prompt) and boom, it will appear your message. Voila ! So I think your code's perfect for what you want to do.

Still, just an (additional) idea, it would be cool to add a message telling the user when he/she's wrong, right?