In this challenge, I want to add a feature that play/pause the sound by pressing space button two times:
I tried to add this functionality, but I couldn’t. I want help to do this functionality.
You can check the audio.paused
property (MDN: paused) and either call play or pause depending on if it is true or not.
document.addEventListener("keydown", (e) => {
if (e.key === " ") {
audio.paused ? audio.play() : audio.pause();
}
})
1 Like
system
Closed
3
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.