<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Time Timer</title>
<style>
#timer {
font-size: 2em;
text-align: center;
margin-top: 50px;
}
</style>
</head>
<body>
<div id="timer">25:00</div>
<button onclick="startTimer()">Start</button>
<button onclick="resetTimer()">Reset</button>
<script>
let timeLeft = 25 * 60; // Set initial time (25 minutes)
let timerInterval;
function startTimer() {
timerInterval = setInterval(() => {
if (timeLeft > 0) {
timeLeft--;
document.getElementById("timer").textContent = formatTime(timeLeft);
} else {
clearInterval(timerInterval);
alert("Time's up!");
}
}, 1000);
}
function resetTimer() {
clearInterval(timerInterval);
timeLeft = 25 * 60;
document.getElementById("timer").textContent = "25:00";
}
function formatTime(seconds) {
let minutes = Math.floor(seconds / 60);
let secs = seconds % 60;
return `${minutes}:${secs < 10 ? '0' : ''}${secs}`;
}
</script>
</body>
</html>