Skip to content

Commit fc9030b

Browse files
committed
play audio on keypress
1 parent 2797c13 commit fc9030b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

01 - JavaScript Drum Kit/index-PROGRESS.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@
5858
<audio data-key="76" src="sounds/tink.wav"></audio>
5959

6060
<script>
61-
window.addEventListener("keydown"), function(e) {
62-
console.log(e);
63-
}
61+
window.addEventListener("keydown", function(e) {
62+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
63+
if (!audio) return; // will stop the function from running.
64+
console.log(audio);
65+
audio.play();
66+
});
6467
</script>
6568

6669

0 commit comments

Comments
 (0)