Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.