Found such a timer code on js:

const second = 1000,//ms minute = second * 60, hour = minute * 60, day = hour * 24; let countDown = new Date('Sep 30, 2019 00:00:00').getTime(), x = setInterval(function() { let 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); }, second) 

Please explain why you can’t just take a date and count from it without using distance ? I also changed math.floor to math.round then completely different numbers were, how to understand what to use? And the last question, why is the balance taken there % ? Thanks in advance.

  • why it is impossible to just take a date and count it off without using distance? - why not? - Grundy
  • changed math.floor to math.round then completely different numbers - see what math.floor does and what math.round does - Grundy
  • why is the remainder taken there% - and what should there be taken instead of the remainder? - Grundy
  • @Grundy I used math.round , and there instead of 658 -> 659 , that is, why exactly the floor . And about the remainder, I do not understand why it is also impossible to share, why use it? Thank. - Timur
  • Did you see what math.floor does, and what math.round do? The above links to the description of these functions. - Grundy

0