Update Countdown Timer

This commit is contained in:
LSvekis
2021-09-06 12:39:19 -04:00
committed by GitHub
parent 0f11d4b093
commit 4c1842233d
+25 -22
View File
@@ -1,23 +1,26 @@
const endDate = "Sept 1 2022"; const endDate = "Sept 1 2022";
update(); update();
function update() {
const temp = countdown(); function update() {
for (const property in temp) { const temp = countdown();
console.log(`${property}: ${temp[property]}`); let output = "";
} for (const property in temp) {
window.setTimeout(update, 1000); output += (`${property}: ${temp[property]} `);
} }
function countdown() { console.log(output);
const total = Date.parse(endDate) - new Date(); setTimeout(update, 1000);
const days = Math.floor(total / (1000 * 60 * 60 * 24)); }
const hrs = Math.floor((total / (1000 * 60 * 60)) % 24);
const mins = Math.floor((total / 1000 / 60) % 60); function countdown() {
const secs = Math.floor((total / 1000) % 60); const total = Date.parse(endDate) - new Date();
return { const days = Math.floor(total / (1000 * 60 * 60 * 24));
total, const hrs = Math.floor((total / (1000 * 60 * 60)) % 24);
days, const mins = Math.floor((total / 1000 / 60) % 60);
hrs, const secs = Math.floor((total / 1000) % 60);
mins, return {
secs days,
}; hrs,
} mins,
secs
};
}