Users can start, stop, and reset the stopwatch. The stopwatch displays the elapsed time in hours, minutes, seconds, and milliseconds. Users can click the “Start”, “Stop”, and “Reset” buttons to control the stopwatch.
function startStopwatch() { if (!running) { startTime = new Date().getTime(); stopwatchInterval = setInterval(updateTime, 10); running = true; } }
function stopStopwatch() { clearInterval(stopwatchInterval); running = false; }
function resetStopwatch() { clearInterval(stopwatchInterval); document.getElementById('time').innerHTML = '00:00:00'; running = false; }
function updateTime() { const currentTime = new Date().getTime(); const elapsedTime = currentTime - startTime; const hours = Math.floor(elapsedTime / (1000 * 60 * 60)); const minutes = Math.floor((elapsedTime % (1000 * 60 * 60)) / (1000 * 60)); const seconds = Math.floor((elapsedTime % (1000 * 60)) / 1000); const milliseconds = Math.floor((elapsedTime % 1000) / 10);
const formattedTime = `${formatTime(hours)}:${formatTime(minutes)}:${formatTime(seconds)}:${formatTime(milliseconds)}`; document.getElementById('time').innerHTML = formattedTime; }
function formatTime(time) { return time < 10 ? `0${time}` : time; }
NathTech Guid, Introduction to Toncoin (TON) Toncoin (TON) is the native cryptocurrency of The…
NathTech Guide , Introduction: glowing skin is a reflection of overall health and self-care. While…
NathTech Guid Introduction: Achieving glowing skin is a goal that many people aspire to, but…
Nathtech Guideline , Introduction Maintaining fitness is crucial for a healthy and fulfilling life, regardless…
Nathtech Guideline , Introduction ; In today's fast-paced world, maintaining fitness is more than…
Nathtech's Guideline , Introduction , In a world that is increasingly focused on…