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

Alex Pascoe
Alex Pascoe
1,595 Points

Math.random. Can't generate random number between 2 pre-defined numbers

Please help me with my code. I really can't seem to crack this one. For some reason it won't appear in the browser. Is my syntax correct?

var input = prompt('Please type a high number');
var topNumber = parseInt(input);
var input1 = prompt('Please type a lower second number');
var bottomNumber = parseInt(input1);
var randomNumber = Math.floor(Math.random() * (topNumber - bottomNumber + 1)) + bottomNumber;
var message = "<p>" + randomNumber + " Is your random generated number between " + bottomNumber " and " + topNumber + ".</p>;
document.write(message);

1 Answer

Hey Alex,

You just got a few typos while constructing the message variable. It should look like this:

var message = "<p>" + randomNumber + " Is your random generated number between " + bottomNumber + " and " + topNumber + ".</p>";