Hi there,
This is done using closure, but when I click on deactivate counting, removeEventListener don’t work.
const countClicks = () => {
let counter = 0
return count = () => {
counter += 1
console.log(counter);
countElement.textContent = counter;
}
}
// start counting
btnElement.addEventListener("click", countClicks()); // <-- here the function is invoke because of the inner function, after its execution the inner function is assigned to the click event handler.
// stop counting
stopCountElement.addEventListener("click", () => {
btnElement.removeEventListener("click", countClicks); // <-- here the function is invoke because of the inner function, after its execution the inner function is assigned to the click event handler.
})