From 56ea98c3d7b63c82a834f254c9fd4aca13597528 Mon Sep 17 00:00:00 2001 From: Karan <50290386+Sonawane-Karan26@users.noreply.github.com> Date: Wed, 24 Nov 2021 21:12:31 +0530 Subject: [PATCH] Project 2 --- Chapter 8/Project 2 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Chapter 8/Project 2 diff --git a/Chapter 8/Project 2 b/Chapter 8/Project 2 new file mode 100644 index 0000000..863549f --- /dev/null +++ b/Chapter 8/Project 2 @@ -0,0 +1,27 @@ +const endDate = "Sept 1 2022"; + +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 + }; +} + +function update() { + const temp = countdown(); + let output = ""; + for (const property in temp) { + output += (`${property}: ${temp[property]} `); + } + console.log(output); + setTimeout(update, 1000); +} + +update();