Last active
March 11, 2024 16:16
-
-
Save giufus/5e2ba6f1a11e97f3b127e5cb28fa4957 to your computer and use it in GitHub Desktop.
countdown 45
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
<!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> | |
<style> | |
.countdown { | |
font-size: 24px; | |
color: greenyellow; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="countdown" id="countdown"></div> | |
<script> | |
// Set the countdown time in seconds | |
var timeLeft = 45; | |
// Function to update the countdown timer | |
function updateCountdown() { | |
var countdownElement = document.getElementById("countdown"); | |
countdownElement.innerHTML = "Time left: " + timeLeft + " seconds"; | |
// If the countdown has reached 0, stop it | |
if (timeLeft === 0) { | |
clearInterval(timer); | |
countdownElement.innerHTML = "Time's up!"; | |
} else { | |
timeLeft--; // Decrease the time left | |
} | |
} | |
// Initial call to update the countdown | |
updateCountdown(); | |
// Update the countdown every second | |
var timer = setInterval(updateCountdown, 1000); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment