From ec677f3b99e3dd6b47a7bba23e79cc5808f41450 Mon Sep 17 00:00:00 2001 From: Jonathan Branan Date: Mon, 2 Sep 2024 11:52:00 -0500 Subject: [PATCH] created stop watch --- d.html | 16 ++++++++++++++++ d.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 d.html create mode 100644 d.js diff --git a/d.html b/d.html new file mode 100644 index 0000000..4411716 --- /dev/null +++ b/d.html @@ -0,0 +1,16 @@ + + + + + + Stop Watch + + +

Stop Watch

+

00:00

+ + + + + + \ No newline at end of file diff --git a/d.js b/d.js new file mode 100644 index 0000000..4d256d5 --- /dev/null +++ b/d.js @@ -0,0 +1,33 @@ +let secondsElapsed = 0 +let interval = null + +const time = document.getElementById("time") + +function padStart(value) { + return String(value).padStart(2, "0") +} +function setTime() { + const minutes = Math.floor(secondsElapsed / 60) + const seconds = secondsElapsed % 60 + time.innerHTML = `${padStart(minutes)}:${padStart(seconds)}` +} + +function timer(){ + secondsElapsed ++ + setTime() +} + +function startClock() { + if (interval) resetClock() + interval = setInterval(timer, 1000) +} + +function stopClock() { + clearInterval(interval) +} + +function resetClock() { + stopClock() + secondsElapsed = 0 + setTime() +} \ No newline at end of file