From 1299635b443b876b50a0e3e9324e9bc2b72d7205 Mon Sep 17 00:00:00 2001 From: Michael Nolan Date: Mon, 17 Oct 2022 08:56:16 +0000 Subject: [PATCH] Original Commit --- js/stopwatch.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 js/stopwatch.js diff --git a/js/stopwatch.js b/js/stopwatch.js new file mode 100644 index 0000000..a3ad693 --- /dev/null +++ b/js/stopwatch.js @@ -0,0 +1,48 @@ +var isStarted=false; +var number=0; +var noLaps=0; +const counter=document.getElementById('counter'); +const startStop2 = document.getElementById('startStopBtn'); +const laps = document.getElementById('laps'); +function startStop() +{ + isStarted = !isStarted; + startStop2.innerText = isStarted ? "Stop" : "Start"; +} +function number2ts(number) +{ + var ms = number % 1000; + + var totalsec = (number - ms) / 1000; + var sec = totalsec % 60; + var totalMin = (totalsec - sec) / 60; + var min = totalMin % 60; + var totalHour = (totalMin - min) / 60; + return `${totalHour}:${min.toString().padStart(2,'0')}:${sec.toString().padStart(2,'0')}.${ms.toString().padStart(3,'0')}`; +} +function lap() +{ + noLaps++; + laps.innerText += `${noLaps}: ${number2ts(number)}\n`; +} +function reset() +{ + counter.innerText=`0:00:00.000`; + noLaps = 0; + number = 0; + laps.innerText=""; +} + +function tick() +{ + + if(isStarted) + { + number+=25; + counter.innerText = number2ts(number); + + } + setTimeout(tick,25); +} + +setTimeout(tick,25); \ No newline at end of file