-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Countdown Timer to the website , Added SWOC labels , Intermediate level to this PR @dhairyagothi Day 81 : CountDown Timer Screenrecording : ![Screenshot 2025-01-05 163818](https://github.com/user-attachments/assets/09e86cb3-da52-43ed-9e31-3f35fdc12900) https://github.com/user-attachments/assets/fe8cc932-5cad-499c-bfe3-705b55d6fad7
- Loading branch information
Showing
4 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Countdown Timer</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="countdown-container"> | ||
<h1>Countdown Timer</h1> | ||
<div id="countdown"> | ||
<span id="days">00</span> Days | ||
<span id="hours">00</span> Hours | ||
<span id="minutes">00</span> Minutes | ||
<span id="seconds">00</span> Seconds | ||
</div> | ||
<div class="controls"> | ||
<button id="start">Start</button> | ||
<button id="pause">Pause</button> | ||
<button id="reset">Reset</button> | ||
</div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
document.addEventListener("DOMContentLoaded", () => { | ||
let countdownInterval; | ||
let elapsedTime = 0; // Start from 0 seconds | ||
|
||
const daysElement = document.getElementById("days"); | ||
const hoursElement = document.getElementById("hours"); | ||
const minutesElement = document.getElementById("minutes"); | ||
const secondsElement = document.getElementById("seconds"); | ||
|
||
const startButton = document.getElementById("start"); | ||
const pauseButton = document.getElementById("pause"); | ||
const resetButton = document.getElementById("reset"); | ||
|
||
const updateCountdown = () => { | ||
const days = Math.floor(elapsedTime / (1000 * 60 * 60 * 24)); | ||
const hours = Math.floor((elapsedTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); | ||
const minutes = Math.floor((elapsedTime % (1000 * 60 * 60)) / (1000 * 60)); | ||
const seconds = Math.floor((elapsedTime % (1000 * 60)) / 1000); | ||
|
||
daysElement.textContent = days.toString().padStart(2, "0"); | ||
hoursElement.textContent = hours.toString().padStart(2, "0"); | ||
minutesElement.textContent = minutes.toString().padStart(2, "0"); | ||
secondsElement.textContent = seconds.toString().padStart(2, "0"); | ||
}; | ||
|
||
const startCountdown = () => { | ||
clearInterval(countdownInterval); // Prevent multiple intervals | ||
countdownInterval = setInterval(() => { | ||
elapsedTime += 1000; // Increment elapsed time by 1 second | ||
updateCountdown(); | ||
}, 1000); | ||
}; | ||
|
||
const pauseCountdown = () => { | ||
clearInterval(countdownInterval); // Stop the interval | ||
}; | ||
|
||
const resetCountdown = () => { | ||
clearInterval(countdownInterval); // Stop the interval | ||
elapsedTime = 0; // Reset elapsed time to 0 | ||
updateCountdown(); | ||
}; | ||
|
||
startButton.addEventListener("click", startCountdown); | ||
pauseButton.addEventListener("click", pauseCountdown); | ||
resetButton.addEventListener("click", resetCountdown); | ||
|
||
// Initialize the timer at 0 | ||
updateCountdown(); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
body { | ||
font-family: Arial, sans-serif; | ||
background: linear-gradient(to right, #4facfe, #00f2fe); | ||
color: #fff; | ||
text-align: center; | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
} | ||
|
||
.countdown-container { | ||
background: rgba(0, 0, 0, 0.5); | ||
padding: 20px 40px; | ||
border-radius: 10px; | ||
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); | ||
} | ||
|
||
h1 { | ||
margin-bottom: 20px; | ||
} | ||
|
||
#countdown { | ||
font-size: 2rem; | ||
margin-bottom: 20px; | ||
} | ||
|
||
#countdown span { | ||
font-weight: bold; | ||
margin: 0 5px; | ||
} | ||
|
||
.controls { | ||
display: flex; | ||
justify-content: center; | ||
gap: 10px; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
border: none; | ||
border-radius: 5px; | ||
background-color: #0078ff; | ||
color: white; | ||
font-size: 1rem; | ||
cursor: pointer; | ||
transition: background-color 0.3s; | ||
} | ||
|
||
button:hover { | ||
background-color: #005ecb; | ||
} | ||
|