copy this code
<!DOCTYPE html>
<html>
<head>
<title>Colorful Stopwatch</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
.stopwatch {
width: 200px;
background-color: #fff;
padding: 20px;
border-radius: 5px;
margin: 0 auto;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
.display {
font-size: 24px;
text-align: center;
margin-bottom: 20px;
}
.controls {
text-align: center;
}
.button {
padding: 10px 20px;
font-size: 16px;
background-color: #ff9f43;
border: none;
border-radius: 5px;
color: #fff;
cursor: pointer;
margin-right: 10px;
}
.button:hover {
background-color: #ff7f00;
}
</style>
</head>
<body>
<div class="stopwatch">
<div class="display" id="display">00:00:00</div>
<div class="controls">
<button class="button" id="startButton" onclick="startStopwatch()">Start</button>
<button class="button" id="stopButton" onclick="stopStopwatch()">Stop</button>
<button class="button" id="resetButton" onclick="resetStopwatch()">Reset</button>
</div>
</div>
<script>
var stopwatchInterval;
var milliseconds = 0;
var seconds = 0;
var minutes = 0;
function startStopwatch() {
stopwatchInterval = setInterval(updateStopwatch, 10);
document.getElementById('startButton').disabled = true;
document.getElementById('stopButton').disabled = false;
}
function stopStopwatch() {
clearInterval(stopwatchInterval);
document.getElementById('startButton').disabled = false;
document.getElementById('stopButton').disabled = true;
}
function resetStopwatch() {
clearInterval(stopwatchInterval);
milliseconds = 0;
seconds = 0;
minutes = 0;
updateDisplay();
document.getElementById('startButton').disabled = false;
document.getElementById('stopButton').disabled = true;
}
function updateStopwatch() {
milliseconds += 10;
if (milliseconds === 1000) {
milliseconds = 0;
seconds++;
if (seconds === 60) {
seconds = 0;
minutes++;
}
}
updateDisplay();
}
function updateDisplay() {
var displayText = padTime(minutes) + ':' + padTime(seconds) + ':' + padTime(Math.floor(milliseconds / 10));
document.getElementById('display').textContent = displayText;
}
function padTime(time) {
return (time < 10 ? '0' : '') + time;
}
</script>
</body>
</html>