Files
JavaScript-from-Beginner-to…/Chapter 11/ex4
T
2021-06-29 21:11:37 -04:00

24 lines
817 B
Plaintext

const endDate = "Sept 1 2022";
update();
function update() {
const temp = countdown();
for (const property in temp) {
console.log(`${property}: ${temp[property]}`);
}
window.setTimeout(update, 1000);
}
function countdown() {
const total = Date.parse(endDate) - new Date();
const days = Math.floor(total / (1000 * 60 * 60 * 24));
const hours = Math.floor((total / (1000 * 60 * 60)) % 24);
const minutes = Math.floor((total / 1000 / 60) % 60);
const seconds = Math.floor((total / 1000) % 60);
return {
total,
days,
hours,
minutes,
seconds
};
}