I am currently doing a simple rock, paper, scissors game with javascript however, removeEventListener() doesn't seem to be working in my code. I know I used a loop to apply the event listeners to the buttons, so I will figure out the loop to remove them later.
For now, I don't understand why my code won't remove the event listener on the button that's clicked:
let btns = document.querySelectorAll('button');
btns.forEach(function(item) {
item.addEventListener('click', function(event) {
results.textContent = '';
playRound(event.target.className, getComputerChoice());
if (playerCount == 5) {
item.removeEventListener('click', event);
winner.textContent = `YOU WON 5 GAMES!`;
}else if (cpuCount == 5) {
item.removeEventListener('click', event);
winner.textContent = `YOU LOSE! CPU WINS 5`;
}
});
});