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

Daniel smith
Daniel smith
1,248 Points

random number challenge not working

Hi this is my code as I tried copying it from the example. however the prompt box comes up then nothing happens. what is wrong with it? thank you

var input=prompt('please type a number');
var topnumber= ParseInt(input);
var randomnumber= Math.floor(Math.random()*topnumber) +1;
var message ='<p>'+randomnumber+'is a number between 1 and'+topnumber+ '</p>';
document.write(message);

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,705 Points

Hi Daniel,

It looks like you're almost there you just need to use the parseInt method properly, with is in camelCase with a lowercase p. Try the following it should work properly. :)

var input=prompt('please type a number');
var topnumber= parseInt(input);
var randomnumber= Math.floor(Math.random()*topnumber) +1;
var message ='<p>'+randomnumber+'is a number between 1 and'+topnumber+ '</p>';
document.write(message);

By the way I changed your original post to show it in JavaScript format. Checkout the markdown cheatsheet link below for tips on how to add code to your posts :)

Daniel smith
Daniel smith
1,248 Points

thank you Jonathan, that worked! can't believe I spent so long trying to fix my code when it was something that simple.