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 Basics (Retired) Working With Numbers The Random Challenge Solution

Andrew Chung
Andrew Chung
5,203 Points

Prompt not appearing

From what I can tell my code is identical to the code shown in the video, however I can't get the first step to show up. When I load the page the prompt doesn't appear.

var input = prompt("Pick a number"); var topNumber = parseInt(input); var randomNumber = Math.floor(Math.random() * topNumber) + 1; var message = "<p>" randomNumber + " is a number between 1 and " + topNumber + ".</p>"; document.write(message);

2 Answers

Bart Bruneel
Bart Bruneel
27,212 Points

Hello Andrew,

there seems to be a + sign missing before randomNumber, like this:

var message = " " + randomNumber + " is a number between 1 and " + topNumber + "."; 

That will do the trick.

Happy coding!

Andrew Chung
Andrew Chung
5,203 Points

Thanks, I really need to watch for these syntax errors.

Tom Sager
Tom Sager
18,987 Points

This portion of your code is not well formed:

 message = "" randomNumber

Try looking at the page in the debugger. In most browsers you can right-click on the page and select "Inspect Element". Then look for the console window, and check any error messages there.

Andrew Chung
Andrew Chung
5,203 Points

I didn't even see that. These syntax errors get me so often. Thanks for pointing it out.