Create random number with javascript - Javascript Data Type

Javascript examples for Data Type:Number

Description

Create random number with javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from w w w .  java2s .  c  o m
var numb1 = Math.floor(Math.random()*100)+1,
    numb2 = 0;
console.log('numb 1 : ' + numb1);

while (numb2<numb1) {
    numb2 = Math.floor(Math.random()*100)+2;
}

console.log('numb 2 : ' + numb2);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials