From 1a835c146100ee40e0d3941c142c2bf595e5bfbc Mon Sep 17 00:00:00 2001 From: gitcommitshow <56937085+gitcommitshow@users.noreply.github.com> Date: Mon, 20 Nov 2023 21:59:33 +0530 Subject: [PATCH 1/2] fix: count js console error --- assets/js/count.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/assets/js/count.js b/assets/js/count.js index 9150cf8..d18d345 100644 --- a/assets/js/count.js +++ b/assets/js/count.js @@ -4,15 +4,14 @@ minute = second * 60, hour = minute * 60, day = hour * 24; -var countDown = new Date('Nov 27, 2021 10:00:00').getTime(), +var countDown = new Date('Jan 27, 2024 10:00:00').getTime(), x = setInterval(function() { - -var now = new Date().getTime(), - distance = countDown - now; - -document.getElementById('days').innerText = Math.floor(distance / (day)), - document.getElementById('hours').innerText = Math.floor((distance % (day)) / (hour)), - document.getElementById('minutes').innerText = Math.floor((distance % (hour)) / (minute)), - document.getElementById('seconds').innerText = Math.floor((distance % (minute)) / second); - + var now = new Date().getTime(), + distance = countDown - now; + if(distance > 0){ + document.getElementById('days').innerText = Math.floor(distance / (day)), + document.getElementById('hours').innerText = Math.floor((distance % (day)) / (hour)), + document.getElementById('minutes').innerText = Math.floor((distance % (hour)) / (minute)), + document.getElementById('seconds').innerText = Math.floor((distance % (minute)) / second); + } }, second) From f636963dd0274cf3b14a4b54051ba3da29ab5733 Mon Sep 17 00:00:00 2001 From: gitcommitshow <56937085+gitcommitshow@users.noreply.github.com> Date: Mon, 20 Nov 2023 22:13:16 +0530 Subject: [PATCH 2/2] fix: add null check --- assets/js/count.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/assets/js/count.js b/assets/js/count.js index d18d345..a80fc57 100644 --- a/assets/js/count.js +++ b/assets/js/count.js @@ -9,9 +9,14 @@ x = setInterval(function() { var now = new Date().getTime(), distance = countDown - now; if(distance > 0){ - document.getElementById('days').innerText = Math.floor(distance / (day)), - document.getElementById('hours').innerText = Math.floor((distance % (day)) / (hour)), - document.getElementById('minutes').innerText = Math.floor((distance % (hour)) / (minute)), - document.getElementById('seconds').innerText = Math.floor((distance % (minute)) / second); + var daysElement = document.getElementById('days'), + hoursElement = document.getElementById('hours'), + minutesElement = document.getElementById('minutes'), + secondsElement = document.getElementById('seconds'); + + if(daysElement) daysElement.innerText = Math.floor(distance / (day)); + if(hoursElement) hoursElement.innerText = Math.floor((distance % (day)) / (hour)); + if(minutesElement) minutesElement.innerText = Math.floor((distance % (hour)) / (minute)); + if(secondsElement) secondsElement.innerText = Math.floor((distance % (minute)) / second); } }, second)