Created
November 9, 2021 13:43
-
-
Save AnInternetTroll/171e9e32d18c1760099f274c824e0ebb to your computer and use it in GitHub Desktop.
A timer that counts down from 100 while showing odd numbers in red and even numbers in green
This file contains hidden or 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> | |
<title></title> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<style> | |
.blue { | |
color: blue !important; | |
} | |
.red { | |
color: red; | |
} | |
h1 { | |
color: green; | |
font-size: 20rem; | |
display: inline-block; | |
margin: auto; | |
} | |
body { | |
padding: 0; | |
margin: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<main> | |
<h1 id="timer">100</h1> | |
</main> | |
<script> | |
const timerEl = document.querySelector("#timer"); | |
let i = parseInt(timerEl.innerText); | |
let timerId = setInterval(() => { | |
timerEl.innerText = --i; | |
if (i % 2 !== 0) timerEl.classList.add("red"); | |
else timerEl.classList.remove("red"); | |
}, 1000); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment