Visitar URL original
I had forgotten how much I love document.qsa · wesbos/JavaScript30@0b6f286 · GitHub
Skip to content

Commit 0b6f286

Browse files
committed
I had forgotten how much I love document.qsa
1 parent 4ca83fd commit 0b6f286

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎01 - JavaScript Drum Kit/index-START.html‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,17 @@
5959

6060
<script>
6161
window.addEventListener('keydown', function(event){
62-
const audio= document.querySelector(`audio[data-key]=${event.keyCode}`)
62+
const audio= document.querySelector(`audio[data-key="${event.keyCode}"]`)
6363
console.log(audio)
64+
const key= document.querySelector(`.key[data-key="${event.keyCode}"]`)
65+
console.log(key)
66+
if (!audio) return //exits the function
67+
audio.currentTime = 0 // should rewind time so that each sound can be played multiple times
68+
audio.play()// method that plays the audio on selected keyCode
69+
key.classList.add('playing')
6470
})
71+
72+
const keys = document.querySelectorAll('.key')
6573
</script>
6674

6775

0 commit comments

Comments
 (0)