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

my random number program is not working

var limit = prompt('type a number?');
var top = parseInt(limit);
var answer = Math.floor(Math.random() * top) + 1;
var message="<p>"+ answer +"is a random number between 0 and " + top +".</p>";
Document.write(message);

The above program is not working for me.please guide.

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hi Muzammil, just to let you know I have reformatted the code.

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hi.

I noticed a couple of things that you should sort out:

1) Don't use a capital letter in document.write() 2) According to this: http://www.w3schools.com/js/js_reserved.asp you must not use top as a name for your variables, try something like topMargin. 3) make sure you substitute the variable name everywhere where you have used it 4) you want to make sure you check your message var, you miss a few spaces here and there.

Vitto

Ivan Saveliev
Ivan Saveliev
9,153 Points

As far as I understood JavaScript doesn't care about spaces inside of the declaration.