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

Faraz Hasan
Faraz Hasan
4,596 Points

Need help!!

This is driving me nuts! Can someone please tell me what I'm doing wrong!? I get the prompt, then nothing.

Thanks!

var userNum = prompt('Give me a random number');
var randomNum = parseInt(userNum);
var alertNum = Math.Floor(Math.Random() * randomNum) + 1;
document.write(alertNum); 

Also how do I write this in a code box!? XD soz for dumbass q's

2 Answers

Collin Perkins
Collin Perkins
8,811 Points

You have Floor and Random capitalized, try making them lowercase (floor, random).

should be Math.floor and Math.random

And to write like what is below just read the Markdown Cheatsheet below the Add an Answer text box. Right above post answer.

var userNum = prompt('Give me a random number');
Faraz Hasan
Faraz Hasan
4,596 Points
<h1> thank you for your help mate you're my hero </h1>
Collin Perkins
Collin Perkins
8,811 Points

No problem glad everything is working.