Mega Code Archive

 
Categories / JavaScript Tutorial / Math
 

Generate a random integer between 2 and 10

< html> <head> <title>Example</title> </head> <body> <script type="text/javascript"> function selectFrom(startValue, endValue) {     var iChoices = endValue - startValue + 1;     return Math.floor(Math.random() * iChoices + startValue); } var iNum = selectFrom(2, 10); alert(iNum); </script> </body> </html>