Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function timer() {
- let timer;
- let seconds = 0;
- let minutes = 0;
- let hours = 0;
- let isRunning = false;
- $('#start-timer').on('click', function (){if (!isRunning){timer = setInterval(step, 1000); isRunning=true;}});
- $('#stop-timer').on('click', function (){if (isRunning){clearInterval(timer); isRunning=false;}});
- function step() {
- seconds++;
- if (seconds > 59)
- {
- seconds = 0;
- minutes++;
- }
- if (minutes > 59)
- {
- minutes = 0;
- hours++;
- }
- $('#seconds')["0"].textContent = padZero(seconds);
- $('#minutes')["0"].textContent = padZero(minutes);
- $('#hours')["0"].textContent = padZero(hours);
- }
- function padZero(n) {if (n < 10) {return ("0" + n);} else {return n;}}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement