Skip to content

Commit 4f2438a

Browse files
committed
Countdown added
1 parent f5f8747 commit 4f2438a

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

CountDownTimer/Jagm33t/index.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Countdown Timer</title>
5+
<link rel="stylesheet" type="text/css" href="style.css">
6+
</head>
7+
<body>
8+
<div id="countdown">
9+
<h1 id="timer"></h1>
10+
<button id="startButton">Start</button>
11+
<button id="pauseButton">Pause</button>
12+
<button id="resetButton">Reset</button>
13+
</div>
14+
<script src="index.js"></script>
15+
</body>
16+
</html>

CountDownTimer/Jagm33t/index.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
document.addEventListener('DOMContentLoaded', function () {
2+
var targetDate = new Date("Dec 31, 2023 23:59:59").getTime();
3+
var countdownFunction;
4+
var paused = false;
5+
var pausedTime;
6+
7+
function updateTimer() {
8+
var now = new Date().getTime();
9+
var distance = targetDate - now;
10+
11+
if (paused) {
12+
distance = pausedTime;
13+
}
14+
15+
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
16+
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
17+
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
18+
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
19+
20+
document.getElementById("timer").innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
21+
22+
if (distance < 0) {
23+
clearInterval(countdownFunction);
24+
document.getElementById("timer").innerHTML = "EXPIRED";
25+
}
26+
}
27+
28+
document.getElementById("startButton").addEventListener("click", function() {
29+
if (!countdownFunction) {
30+
countdownFunction = setInterval(updateTimer, 1000);
31+
}
32+
if (paused) {
33+
targetDate = new Date().getTime() + pausedTime;
34+
paused = false;
35+
}
36+
});
37+
38+
document.getElementById("pauseButton").addEventListener("click", function() {
39+
if (!paused) {
40+
pausedTime = targetDate - new Date().getTime();
41+
clearInterval(countdownFunction);
42+
countdownFunction = null;
43+
paused = true;
44+
}
45+
});
46+
47+
document.getElementById("resetButton").addEventListener("click", function() {
48+
paused = false;
49+
clearInterval(countdownFunction);
50+
countdownFunction = null;
51+
targetDate = new Date("Dec 31, 2023 23:59:59").getTime();
52+
updateTimer();
53+
});
54+
55+
updateTimer();
56+
});

CountDownTimer/Jagm33t/readme.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Countdown Timer
2+
3+
### Built Using
4+
<ul>
5+
<li>HTML</li>
6+
<li>CSS</li>
7+
<li>Javascript</li>
8+
</ul>

CountDownTimer/Jagm33t/style.css

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
body {
2+
font-family: Arial, sans-serif;
3+
display: flex;
4+
justify-content: center;
5+
align-items: center;
6+
height: 100vh;
7+
background-color: #f0f0f0;
8+
}
9+
10+
#countdown {
11+
text-align: center;
12+
}
13+
14+
#timer {
15+
font-size: 50px;
16+
color: #333;
17+
margin-bottom: 20px;
18+
}
19+
20+
button {
21+
font-size: 16px;
22+
padding: 10px 20px;
23+
margin: 5px;
24+
border: none;
25+
border-radius: 5px;
26+
background-color: #4CAF50;
27+
color: white;
28+
cursor: pointer;
29+
transition: background-color 0.3s;
30+
}
31+
32+
button:hover {
33+
background-color: #45a049;
34+
}
35+
36+
button:active {
37+
background-color: #3e8e41;
38+
}

0 commit comments

Comments
 (0)