Original Commit

This commit is contained in:
Michael Nolan 2022-10-17 08:56:16 +00:00
parent 39fd5b9d99
commit 1299635b44
1 changed files with 48 additions and 0 deletions

48
js/stopwatch.js Normal file
View File

@ -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);