diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..b68ddc18c5 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -57,9 +57,7 @@ - +
@@ -15,59 +16,6 @@ - - - - +diff --git a/01 - JavaScript Drum Kit/js/app.js b/01 - JavaScript Drum Kit/js/app.js new file mode 100644 index 0000000000..49d26de55d --- /dev/null +++ b/01 - JavaScript Drum Kit/js/app.js @@ -0,0 +1,20 @@ +function playSound(e) { + const audio = document.querySelector(`audio[data-key= "${e.keyCode}"]`); + const key = document.querySelector(`.key[data-key= "${e.keyCode}"]`); + console.log(audio); + if (!audio) return; // stop the function from running + audio.currentTime = 0; // rewind to the start + audio.play(); + key.classList.add('playing'); +} + +function removeTransition(e) { + if(e.propertyName !== 'transform') return; // skip if it's not a transform + + this.classList.remove('playing'); +} + +const keys = document.querySelectorAll('.key'); +keys.forEach(key => key.addEventListener('transitionend', removeTransition)); + +window.addEventListener('keydown', playSound); diff --git a/02 - JS + CSS Clock/index-START.html b/02 - JS + CSS Clock/index-START.html index 2712384201..164bbe2875 100644 --- a/02 - JS + CSS Clock/index-START.html +++ b/02 - JS + CSS Clock/index-START.html @@ -3,6 +3,7 @@
+