diff --git a/index.html b/index.html index e5b3619..3770cc1 100644 --- a/index.html +++ b/index.html @@ -8,11 +8,12 @@ - -∞∞ Days
-∞∞ Hours
-∞∞ Minutes
-∞∞ Seconds
+ +∞∞ Days
+∞∞ Hours
+∞∞ Minutes
+∞∞ Seconds
+
\ No newline at end of file diff --git a/main.js b/main.js index db2fda6..394fffe 100644 --- a/main.js +++ b/main.js @@ -1,11 +1,9 @@ -const target = new Date(location.hash.substr(1)); - const second = 1000; const minute = second*60; const hour = minute*60; const day = hour*24; -const update_countdown = () => { +const countdown = (target) => { const now = new Date(); const diff = target - now; @@ -15,15 +13,24 @@ const update_countdown = () => { timeleft.minutes = Math.trunc(diff%day%hour/minute); timeleft.seconds = Math.trunc(diff%day%hour%minute/second); - Object.keys(timeleft).forEach((unit) => { + const formatted = Object.keys(timeleft).map((unit) => { // retrieve value, cast it to string and optionally pad it with a leading 0 - const value = timeleft[unit] + return timeleft[unit] .toString() .padStart(2, '0'); - - document.getElementById(unit).innerHTML = value; }); + + return ` +${formatted[0]} Days
+${formatted[1]} Hours
+${formatted[2]} Minutes
+${formatted[3]} Seconds
+`; }; -update_countdown(); -setInterval(update_countdown, 500); \ No newline at end of file +const hash_date = new Date(location.hash.substr(1)) +const update_all = () => { + document.getElementById('output').innerHTML = countdown(hash_date); +} +update_all(); +setInterval(update_all, 500); \ No newline at end of file