Skip to content

Commit ba41dae

Browse files
committed
added verboose comments to drum kit exercise
1 parent f1e6a80 commit ba41dae

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

01 - JavaScript Drum Kit/index-START.html

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,25 @@
6060
function playSound(e) {
6161
const audio = document.querySelector(`audio[code="${event.code}"]`);
6262
const key = document.querySelector(`.key[code="${event.code}"]`);
63-
if (!audio) return; // stop function from running all together
64-
audio.currentTime = 0; // rewind to the start
65-
audio.play();
66-
key.classList.add('playing');
63+
if (!audio) return; // stop function from running all together if there is no corresponding code
64+
audio.currentTime = 0; // rewind to the start if clicked while still playing
65+
audio.play(); // when playSound (event) is invoked, play the audio
66+
key.classList.add('playing'); // add the playing classList when event is triggered (and thus function runs)
6767
}
6868

6969
function removeTransition(e) {
70-
if (e.propertyName !== 'transform') return; // skip if it's not transformed
71-
this.classList.remove('playing');
70+
if (e.propertyName !== 'transform') return; // stop function if transform is not active (has finished)
71+
this.classList.remove('playing'); // when removeTransition is called (and transform is no longer active) remove .playing class
7272
}
7373

74-
const keys = document.querySelectorAll('.key');
75-
keys.forEach((key) =>
76-
key.addEventListener('transitionend', removeTransition)
74+
const keys = document.querySelectorAll('.key'); // select the NodeList of all divs with the class .key
75+
keys.forEach(
76+
(
77+
key // for every key in the NodeList
78+
) => key.addEventListener('transitionend', removeTransition) // when event transitionend is triggered, run removeTransition function declared above (removes .playing class)
7779
);
7880

79-
window.addEventListener('keydown', playSound);
81+
window.addEventListener('keydown', playSound); // when key is pressed, invoke playSound function declared above (adds class and plays sound if key matches html code declaration)
8082
</script>
8183
</body>
8284
</html>

0 commit comments

Comments
 (0)