Create ex4
This commit is contained in:
parent
2cd13d7e83
commit
e30542a20d
23
Chapter 11/ex4
Normal file
23
Chapter 11/ex4
Normal 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) - new Date();
|
||||
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);
|
||||
const secs = Math.floor((total / 1000) % 60);
|
||||
return {
|
||||
total,
|
||||
days,
|
||||
hrs,
|
||||
mins,
|
||||
secs
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user