Reputation: 57
How can I reach the variable "count_down", from the other function called "STOP" so I can "clearInterval(count_down)".
Code
function START(){
let count_down = setInterval(countDown, 1000);
up.setAttribute("disabled" , true)
down.setAttribute("disabled" , true)
count.innerHTML = "stop";
return count_down;
}
function STOP(){
clearInterval(count_down)
up.removeAttribute("disabled");
down.removeAttribute("disabled");
count.innerHTML = "start";
}
Troubleshoot:
Uncaught ReferenceError: count_down is not defined
at STOP (main.js:112)
at HTMLButtonElement.count.onclick (main.js:123)
Upvotes: 0
Views: 24
Reputation: 3345
You can do something like this.
let count_down=0;
function START(){
count_down = setInterval(countDown, 1000);
up.setAttribute("disabled" , true)
down.setAttribute("disabled" , true)
count.innerHTML = "stop";
return count_down;
}
function STOP(){
clearInterval(count_down)
up.removeAttribute("disabled");
down.removeAttribute("disabled");
count.innerHTML = "start";
}
Upvotes: 1