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 trialAlex Pascoe
1,595 PointsMath.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
miikis
44,957 PointsHey 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>";