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 trialDaniel smith
1,248 Pointsrandom 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
Treehouse Moderator 91,253 PointsHi 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
1,248 PointsDaniel smith
1,248 Pointsthank you Jonathan, that worked! can't believe I spent so long trying to fix my code when it was something that simple.