commit ec677f3b99e3dd6b47a7bba23e79cc5808f41450 Author: Jonathan Branan Date: Mon Sep 2 11:52:00 2024 -0500 created stop watch 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