Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function timer() {
- let running = false;
- $('#start-timer').click(startTimer);
- $('#stop-timer').click(stopTimer);
- let hours = $('#hours').text();
- let minutes = $('#minutes').text();
- let seconds = $('#seconds').text();
- function startTimer() {
- if (!running) {
- running = true;
- timer = setInterval(step, 1000);
- function step() {
- if (seconds >= 59) {
- seconds = 0;
- minutes++;
- $('#minutes').text(minutes < 10 ? ('0' + minutes.toString()) : minutes);
- }
- if (minutes >= 59) {
- minutes = 0;
- hours++;
- $('#hours').text(hours < 10 ? ('0' + hours.toString()) : hours);
- }
- seconds++;
- $('#seconds').text(seconds < 10 ? ('0' + seconds.toString()) : seconds);
- }
- }
- }
- function stopTimer() {
- if (running) {
- running = false;
- clearInterval(timer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement