Skip to content

Instantly share code, notes, and snippets.

@AnInternetTroll
Created November 9, 2021 13:43
Show Gist options
  • Save AnInternetTroll/171e9e32d18c1760099f274c824e0ebb to your computer and use it in GitHub Desktop.
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
<!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