-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
89 lines (84 loc) · 2.08 KB
/
index.html
File metadata and controls
89 lines (84 loc) · 2.08 KB
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
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Countdown Timer</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
#current-time,
#countdown {
font-size: 24px;
margin: 20px;
}
button {
font-size: 16px;
padding: 10px;
margin: 10px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="current-time">Current time: --:--:--</div>
<div id="countdown">05 min : 00 sec left</div>
<button onclick="startTimer()">Start</button>
<button onclick="stopTimer()">Stop</button>
<button onclick="resetTimer()">Reset</button>
<script>
let timerInterval;
let remainingSeconds = 1200;
function updateTime() {
const now = moment();
document.getElementById(
'current-time',
).innerText = `Current time: ${now.format('hh:mm:ss A')}`;
}
function updateCountdown() {
const countdownMinutes = Math.floor(remainingSeconds / 60);
const countdownSeconds = remainingSeconds % 60;
document.getElementById('countdown').innerText = `${String(
countdownMinutes,
).padStart(2, '0')} min : ${String(countdownSeconds).padStart(
2,
'0',
)} sec left`;
}
function startTimer() {
if (timerInterval) return;
timerInterval = setInterval(() => {
if (remainingSeconds > 0) {
remainingSeconds--;
updateTime();
updateCountdown();
} else {
clearInterval(timerInterval);
timerInterval = null;
resetTimer();
}
}, 1000);
}
function stopTimer() {
clearInterval(timerInterval);
timerInterval = null;
}
function resetTimer() {
stopTimer();
remainingSeconds = 1200;
updateCountdown();
}
updateTime();
updateCountdown();
setInterval(updateTime, 1000);
</script>
<br />
<br />
<hr />
<a href="https://github.com/NarendraJoglekar">@NarendraJoglekar</a>
<br />
</body>
</html>