From 4c1842233df781f0b2962ece76dbce854a162309 Mon Sep 17 00:00:00 2001 From: LSvekis Date: Mon, 6 Sep 2021 12:39:19 -0400 Subject: [PATCH] Update Countdown Timer --- Chapter 8/Countdown Timer | 47 +++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/Chapter 8/Countdown Timer b/Chapter 8/Countdown Timer index 24daa85..7634d94 100644 --- a/Chapter 8/Countdown Timer +++ b/Chapter 8/Countdown Timer @@ -1,23 +1,26 @@ 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 - }; - } +update(); + +function update() { + const temp = countdown(); + let output = ""; + for (const property in temp) { + output += (`${property}: ${temp[property]} `); + } + console.log(output); + 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 { + days, + hrs, + mins, + secs + }; +}