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 trial2 Answers
geoffrey
28,736 PointsTo achieve this you'll often use Math.random() & Math.floor() functions. An exemples:
var nbr1 = Math.floor((Math.random() * 10) + 1); //Return a random number between 1 and 10:
var nrb2 = Math.floor((Math.random() * 100) + 1); // Return a random number between 1 and 100;
Hope this helps.
Garrett Carver
14,681 Pointshere's how I did it:
var userNum = prompt("Enter a number");
var rando = (Math.random() * parseInt(userNum)) + 1;
rando = Math.floor(rando);
alert(rando);