From 5584b87f358c72e3dc1ddcc3f2eb351883f29639 Mon Sep 17 00:00:00 2001 From: LSvekis Date: Tue, 29 Jun 2021 21:08:00 -0400 Subject: [PATCH] Create ex4 --- Chapter 11/ex4 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Chapter 11/ex4 diff --git a/Chapter 11/ex4 b/Chapter 11/ex4 new file mode 100644 index 0000000..9c5e442 --- /dev/null +++ b/Chapter 11/ex4 @@ -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 + }; + }