I wrote the code below to play a sound whenever a key is pressed
window.addEventListener('keydown', ()=> {engineSound.play();})
But when the code is executed, every other thing is frozen and the sound continues playing even though the key is no longer being pressed.
You need to have engineSound.stop() method, and your code should look like this.
window.addEventListener('keydown', ()=> {engineSound.play();})
window.addEventListener('keyup', ()=> {engineSound.stop();})