The year 2020 is not going that much well for anyone, Because of the global pandemic situation, the whole world is kind of of stagnated behind the door. like every other person, I am also eagerly waiting for a new sunshine, a new day finally a new year. So I decided to build a count down clock using html, css, and javascript.

And here it is. I was trying to keep it as simple as possible.

Function Description

function counter(){
    let dateCurrent =  new Date().getTime(),
        timeLeft = newYear - dateCurrent;
     let second = 1000,
        minute = second * 60,
        hour = minute * 60,
        day = hour * 24;
    let dayLeft     =  addZero(Math.floor(timeLeft/ day), 3),
        hourLeft    =  addZero(Math.floor((timeLeft % day)/ hour), 2),
        mintueLeft  =  addZero(Math.floor((timeLeft % hour)/minute), 2),
        secondLeft  =  addZero(Math.floor((timeLeft % minute)/ second), 2)

    function addZero (num, count) {
        return num.toString().padStart(count, "0");
    }

In every call i was counting time left and then calculating it to present it in an meaning full way,

 function addZero (num, count) {
        return num.toString().padStart(count, "0");
    }

And this is adding "0" before the days, hours an so on when the digits will come down to 2/1.

setInterval(() => {
    counter();
}, 1000);

And using this i am calling the counter() function in every 1 sec.

Hope you would like this.