I am new to javascript. I am trying to clear my timer value on clcking the"clear" button.I tried to use the variable"sec" from myTimer function, but it is not working. Any suggestions? Help is appreciated.
the document.getElementsByTagName gets the button and runs the function when clicked.
let timer;
let increment = 0;
timer = setInterval(() => increment++ , 1000)
//gets the button element and clears timer when clicked
document.getElementsByTagName("button").onclick = function() {
clearInterval(timer)
}
let count = 0
let myTimer;
// set timer
myTimer = setInterval(() => count = count + 1 , 1000)
// clear timer
clearInterval(myTimer)
Show the code of your timer so that I can describe the solution in more detail