From 5a1a5261faf9b272f7c76a64c3cd65229b6bd46a Mon Sep 17 00:00:00 2001 From: lub Date: Sun, 21 Jul 2019 11:50:48 +0200 Subject: [PATCH] directly display countdown by extracting the countdown update to a dedicated function we can call it before setting the interval. thus the countdown is updated the instant it is possible instead of needing to wait for the timer interval. --- main.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 40730c0..e6eb6d7 100644 --- a/main.js +++ b/main.js @@ -5,7 +5,7 @@ const minute = second*60; const hour = minute*60; const day = hour*24; -setInterval(() => { +const update_countdown = () => { const now = new Date(); const diff = target - now; @@ -23,4 +23,7 @@ setInterval(() => { document.getElementById(unit).innerHTML = value; }); -}, 500); \ No newline at end of file +}; + +update_countdown(); +setInterval(update_countdown, 500); \ No newline at end of file