Create ex4

This commit is contained in:
LSvekis 2021-06-29 21:08:00 -04:00 committed by GitHub
parent 1cdea3bd9d
commit 5584b87f35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

23
Chapter 11/ex4 Normal file
View File

@ -0,0 +1,23 @@
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) - Date.parse(new Date());
const seconds = Math.floor((total / 1000) % 60);
const minutes = Math.floor((total / 1000 / 60) % 60);
const hours = Math.floor((total / (1000 * 60 * 60)) % 24);
const days = Math.floor(total / (1000 * 60 * 60 * 24));
return {
total,
days,
hours,
minutes,
seconds
};
}