Spaces:
Running
Running
File size: 2,086 Bytes
d2dea51 01bbd0f d2dea51 01bbd0f d2dea51 01bbd0f d2dea51 01bbd0f d2dea51 01bbd0f d2dea51 01bbd0f d2dea51 01bbd0f d2dea51 01bbd0f d2dea51 01bbd0f d2dea51 01bbd0f d2dea51 01bbd0f d2dea51 067e87e d2dea51 01bbd0f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>5-Minute Timer with Controls</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #0a2472;
color: white;
font-family: 'Montserrat', sans-serif;
flex-direction: column;
}
h1 {
font-size: 4rem;
margin: 0;
}
.buttons {
margin-top: 20px;
display: flex;
gap: 15px;
}
button {
padding: 10px 20px;
border: none;
border-radius: 10px;
background-color: #ff7f50;
color: white;
font-size: 1.2rem;
cursor: pointer;
transition: background-color 0.2s;
}
button:hover {
background-color: #ff9966;
}
</style>
</head>
<body>
<h1 id="timer">05:00</h1>
<div class="buttons">
<button onclick="startTimer()">Start</button>
<button onclick="pauseTimer()">Pause</button>
<button onclick="resetTimer()">Restart</button>
</div>
<script>
let time = 300; // 5 minutes in seconds
let timerInterval;
let isRunning = false;
function updateDisplay() {
const minutes = Math.floor(time / 60);
const seconds = time % 60;
document.getElementById('timer').textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
function startTimer() {
if (isRunning) return; // prevent multiple intervals
isRunning = true;
timerInterval = setInterval(() => {
if (time <= 0) {
clearInterval(timerInterval);
document.getElementById('timer').textContent = "TIME'S UP!";
isRunning = false;
return;
}
time--;
updateDisplay();
}, 1000);
}
function pauseTimer() {
clearInterval(timerInterval);
isRunning = false;
}
function resetTimer() {
clearInterval(timerInterval);
time = 300;
isRunning = false;
updateDisplay();
}
updateDisplay();
</script>
</body>
</html>
|