Skip to content

Commit fb7578c

Browse files
committed
Complete JavaScript30 exercises wesbos#1 and wesbos#25
1 parent 00add69 commit fb7578c

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

01 - JavaScript Drum Kit/index-START.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@
5959

6060
<script>
6161

62+
function playSound(e) {
63+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
64+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
65+
66+
if (!audio) return;
67+
audio.currentTime = 0;
68+
audio.play();
69+
key.classList.add('playing');
70+
};
71+
72+
function removeTransition(e) {
73+
if(e.propertyName !== 'transform') return;
74+
this.classList.remove('playing');
75+
};
76+
77+
window.addEventListener('keydown', playSound);
78+
79+
const keys = document.querySelectorAll('.key');
80+
keys.forEach(key => key.addEventListener('transitionend', removeTransition)); // animationend works the same way for animations
81+
82+
6283
</script>
6384

6485

25 - Event Capture, Propagation, Bubbling and Once/index-START.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,22 @@
4141
</style>
4242

4343
<button></button>
44+
4445
<script>
46+
const divs = document.querySelectorAll('div');
47+
48+
function logText(e) {
49+
console.log(this.classList.value);
50+
// e.stopPropagation();
51+
};
52+
53+
divs.forEach(div => div.addEventListener('click', logText, {
54+
capture: false,
55+
// once: true // makes so it runs once and then won't run again until refreshed -- good for store checkouts
56+
}));
4557

4658
</script>
59+
4760
</body>
61+
4862
</html>

0 commit comments

Comments
 (0)