Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. function timer() {
  2. let count = 0;
  3. let time;
  4. let ckliked = true;
  5. //start
  6. $('#start-timer').click(function () {
  7.  
  8. if (ckliked) {
  9. count=0;
  10. counter();
  11.  
  12. time = setInterval(counter, 1000);
  13. ckliked = false;
  14. }
  15. });
  16. //stop
  17. $('#stop-timer').click(function () {
  18. ckliked = true;
  19. clearInterval(time);
  20. });
  21.  
  22. function counter() {
  23.  
  24. let seconds = count % 60;
  25. let minutes = ((count - count % 60) / 60) % 60;
  26. let hours = Math.floor(((count - seconds) / 60) / 60);
  27. $('#seconds').text(('0' + `${seconds}`).slice(-2));
  28. $('#minutes').text(('0' + `${minutes}`).slice(-2));
  29. $('#hours').text(('0' + `${hours}`));
  30. count++;
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement