Hackcraft_
New Coder
I made a game with a simple menu, and now wish that the player can simply press enter to start the game instead of having to click the start button every time. however, I don't want the function to be active during the gameplay. This is my current code
The function works, however, it cannot successfully remove the event listener.
JavaScript:
const startGameOnEnter = function (event) {
console.log(event.key)
if (event.key === 'Enter') {
startGame()
removeEventListener('keydown', startGameOnEnter.bind(KeyboardEvent))
}
}
addEventListener('keydown', startGameOnEnter.bind(KeyboardEvent))
The function works, however, it cannot successfully remove the event listener.