I have a function that displays a count down clock according to a variable. What would be the right way to stop it in the specified condition? clearTimeout is not stoping the Decrement functions.
function interface_vip(type){
var timeout = '';
var clock = '';
//display clock
function Decrement() {
currentMinutes = Math.floor(secs / 60);
currentSeconds = secs % 60;
if(currentSeconds <= 9) currentSeconds = "0" + currentSeconds;
secs--;
if(secs !== -1) timeout = setTimeout(Decrement,1000);
}
if (type == 1){
var mins = 20;
var secs = mins * 60;
var currentSeconds = 0;
var currentMinutes = 0;
clock = setTimeout(Decrement,1000);
}
if (type == 2){
clearTimeout(clock);
clearTimeout(timeout);
}
}
interfaceis a reserved word in JavaScript mathiasbynens.be/notes/reserved-keywords#ecmascript-2