Set up timer for Every 1 second to increase the value with a random number - Javascript Data Type

Javascript examples for Data Type:Number

Description

Set up timer for Every 1 second to increase the value with a random number

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(){//ww w  . j  av a 2 s  .c om
var number = 0;
setInterval (function myFunction() {
  number = number +
  Math.floor((Math.random() * 5) + 1)/100;
  document.getElementById("computerScore").innerHTML = number;
}, 1000)
    }

      </script> 
   </head> 
   <body> 
      <b>computer score:</b>
      <p id="computerScore">0</p>  
   </body>
</html>

Related Tutorials