When the user clicks a button an interval will start counting but the problem is that if the user clicks the button two times there will be two intervals I tried clearInterval(interval);
before assigning the interval but the timer stopped counting.
function times(){
var element=document.getElementById("sec");
counter=0;
let interval= setInterval(myFunction, 1000);
function myFunction(){
counter++;
element.innerHTML=counter;
}
}