I'm trying to make a timer within javascript. I want the timer to stop on click but it won't. I have two parameters: "start" and "stop". I want my program to restart the timer if the start button is clicked while the timer is already going and to stop when the stop button is clicked.
function timer(start, stop) {
let count;
if (start) {
let count = 0;
setInterval(() => {
count++;
console.log(count);
}, 1000);
}
if (stop) {
count = count;
}
}