Advertisement
kristina111

Untitled

Jun 25th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function timer() {
  2.         let tick = 0;
  3.         let clockOn=false;
  4.  
  5.         let myInterval = null;
  6.        
  7.         function step() {
  8.             tick++;
  9.             let seconds = ('0' + tick % 60).slice(-2);
  10.             $('#seconds').text(seconds);
  11.             let minutes = ('0' + Math.floor(tick / 60)).slice(-2);
  12.             $('#minutes').text(minutes);
  13.             let hours = ('0' + Math.floor(minutes / 60)).slice(-2);
  14.             $('#hours').text(hours);
  15.         }
  16.  
  17.         function myStopFunction() {
  18.             clearInterval(myInterval);
  19.             console.log('clear');
  20.         }
  21.  
  22.  
  23.         $('#start-timer').on('click', function(){
  24.             myInterval = setInterval(step, 1000);
  25.         });
  26.  
  27.  
  28.         $('#stop-timer').on('click', myStopFunction);
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement