Can someone assist me with this issue? The stop button only invokes clearInterval() once - what is causing this problem in the code?
var startButton = document.querySelector("#start");
var stopButton = document.querySelector("#stop");
window.addEventListener('load', () => {
function runInterval() {
var time = setInterval(function() {
console.log("Set interval executed");
}, 1500);
return time;
}
var time = runInterval();
stopButton.addEventListener("click", function() {
clearInterval(time);
});
startButton.addEventListener("click", function() {
runInterval();
});
});
<button id="stop"> stop! </button>
<button id="start"> start! </button>