-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathPomodoro Timer
83 lines (83 loc) · 2.04 KB
/
Pomodoro Timer
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
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pomodoro Timer</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="pomodoro-container">
<h1>Pomodoro Timer</h1>
<p id="timerDisplay">25:00</p>
<div class="buttons">
<button id="startButton">Start</button>
<button id="resetButton">Reset</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS:
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.pomodoro-container {
text-align: center;
background-color: #f0f0f0;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
#timerDisplay {
font-size: 48px;
margin: 20px 0;
}
.buttons {
display: flex;
justify-content: center;
gap: 10px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
JavaScript:
let timer;
let timeLeft = 1500; // 25 minutes
let isRunning = false;
function updateDisplay() {
const minutes = Math.floor(timeLeft / 60).toString().padStart(2, '0');
const seconds = (timeLeft % 60).toString().padStart(2, '0');
document.getElementById('timerDisplay').textContent = `${minutes}:${seconds}`;
}
function startTimer() {
if (!isRunning) {
timer = setInterval(function() {
if (timeLeft > 0) {
timeLeft--;
updateDisplay();
} else {
clearInterval(timer);
alert('Time is up!');
}
}, 1000);
isRunning = true;
}
}
function resetTimer() {
clearInterval(timer);
timeLeft = 1500; // Reset to 25 minutes
updateDisplay();
isRunning = false;
}
document.getElementById('startButton').addEventListener('click', startTimer);
document.getElementById('resetButton').addEventListener('click', resetTimer);
updateDisplay();