I need some help, stop button invoke clearInterval() and only works one time, whats wrong in the code?
var start = document.querySelector("#start");
var stop = document.querySelector("#stop");
window.addEventListener('load', () => {
function intervalo() {
var tiempo = setInterval(function() {
console.log("Set interval ejecutado");
}, 1500);
return tiempo;
}
var tiempo = intervalo();
stop.addEventListener("click", function() {
clearInterval(tiempo);
});
start.addEventListener("click", function() {
intervalo();
});
});
<button id="stop"> stop! </button>
<button id="start"> start! </button>