How to remove multiple event listeners at once?

28 views Asked by At

I have buttons for rock,paper and scissors game and each button has an addEventListener attached to them with some function calls inside. How can I remove all event listeners at once for example if an if statement is triggered inside one of the buttons.

button1.addEventListener('click', function myButton1(e) {
    results.textContent = playRound("rock", getComputerChoice())
    score.textContent = ` ${playerScore} - ${computerScore}`
    if (playerScore >= 5 && computerScore >= 5 && playerScore===computerScore) {
        score.textContent = `The game is now over. Final score: ${playerScore} - ${computerScore}. Game ends in a draw!`

If the if-statement triggers I would like to remove all event listeners for all buttons. My buttons are named button1, button2, button3 and listeners myButton1, myButton2, myButton3.

0

There are 0 answers