Set a countdown

I Dont know how to set a countdown, could anyone help me?

1 Like

hello twistedmindgirl, I solved it in my project with a small function hope it works for you.

timeInicial = 120 // TIME TOTAL  
this.timeMax = this.timeInicial;
this.countTime = this.timeMax / 60; //MINUTES 
this.time = 60; //SECONDS
timeClock = function (dt) {
    if (this.timeMax > 0) {
        this.time -= dt;
        if (this.time <= 0) {
            this.countTime -= 1;
            this.time = 59;
        }
        console.log(numberText(this.countTime) + ":" + numberText(this.time.toFixed(0));
        this.timeMax -= dt;
    }
};

numberText = function (a) {
    return a<0?"00":(a > 9 ? a : "0" + a);
};