Here's my take. Simple, short, readable, and unpretentious:
const SECOND = 1000; const MINUTE = 60 * SECOND; const HOUR = 60 * MINUTE; const DAY = 24 * HOUR; setInterval(() => { let diff = Date.parse("Oct 31, 2023 20:00:00") - Date.now(); const days = Math.floor(diff / DAY); diff -= days * DAY; const hours = Math.floor(diff / HOUR); diff -= hours * HOUR; const mins = Math.floor(diff / MINUTE); diff -= mins * MINUTE; const secs = Math.floor(diff / SECOND); document.querySelector("#timer").innerHTML = ` <div>${days}<span>Days</span></div> <div>${hours}<span>Hours</span></div> <div>${mins}<span>Minutes</span></div> <div>${secs}<span>Seconds</span></div>`; }, SECOND);
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's my take.
Simple, short, readable, and unpretentious: