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

I am unable to preview my code (no prompts or alerts come up). What is wrong with my code - can you see?

Hey everyone -

I am unable to preview my code (no prompts or alerts come up). What is wrong with my code - can you see?

Thanks in advance

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

4 Answers

When you attempt to run your program the console states you have a syntax error on line 4.

The issue you are running into is caused by a simple whitespace error. You typed:

random number

When you should have typed:

randomNumber

You have accidentally referenced two nonexistent variables.

Thanks Daniel

Take a look at your message variable. You are concatenating random number instead of the variable randomNumber. I do lots of these typos. The JavaScript console in your browser can help you find them. The message is not always useful, but it tells you which line of code to look at so you can narrow down where an error might be located.

Thank you Erika - great advice regarding the JavaScript console

var input1 = prompt("Gimme the initial value"); var bottomNumber = parseInt(input1); var input = prompt("Please type a number"); var topNumber = parseInt(input); var randomNumber = Math.floor(Math.random() * (topNumber - bottomNumber + 1)) + bottomNumber; var message = "<p>" + randomNumber + " is a number between " + bottomNumber + " and " + topNumber + ".</p>"; document.write(message);

Mine is not working, is it my computer not allowing the 2nd pop up, FIrefox and Edge on Win10 both don't work, and I am getting 408 Request Time-Out alot with this site this week.

James,

Your code works for me with Firefox and Windows 7. So yes, try it from another computer if you can. Are you getting any error messages besides the 408?