Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kemguru authored Aug 7, 2024
1 parent c5adf05 commit 94bf184
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions timer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
let timers = {};
let intervals = {};

function startTimer(timerId) {
if (intervals[timerId]) {
return; // Timer is already running
}

if (!timers[timerId]) {
timers[timerId] = 0;
}

intervals[timerId] = setInterval(() => {
timers[timerId]++;
document.getElementById(timerId).textContent = formatTime(timers[timerId]);
}, 1000);
}

function stopTimer(timerId) {
clearInterval(intervals[timerId]);
intervals[timerId] = null;
}

function resetTimer(timerId) {
stopTimer(timerId);
timers[timerId] = 0;
document.getElementById(timerId).textContent = "00:00";
}

function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
return `${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`;
}

0 comments on commit 94bf184

Please sign in to comment.