Pages

Thursday, 5 October 2017

Timer Java Script


Timer Java Script Banner

A timer like simulation can be creating using setTimeOut function which takes two arguments. code and timer interval in Millisecond. Code run after given time span and if you will call these function in recursive fashion then you can make a watch. 



Timer function Function 



<script>
          var s=0,m=0,h=0;
          function getTimer()
          {
              s++;
              if(s==5) //Minute complete
              {

                   m++;
                   s=0;
              }
              if(m==5)  //Hour Complete
              {
                   h++;
                   m=0;
              }
              document.getElementById('s1').innerHTML=h + ':' + m + ':' + s;
              setTimeout("getTimer()",1000);
          }

     </script>




No comments:

Post a Comment