-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
62 lines (46 loc) · 1.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
$("button").click(function() {
var buttonText = $(this).attr("class")[0];
playSound(buttonText);
buttonPressed(buttonText);
});
$(document).keydown(function(event) {
playSound(event.key);
buttonPressed(event.key);
});
function playSound(key) {
switch (key) {
case "a":
var kick = new Audio('sounds/kick.mp3');
kick.play();
break;
case "s":
var snare = new Audio('sounds/snare.mp3');
snare.play();
break;
case "d":
var hihat = new Audio('sounds/hihat.mp3');
hihat.play();
break;
case "j":
var clap = new Audio('sounds/clap.mp3');
clap.play();
break;
case "k":
var clink = new Audio('sounds/clink.mp3');
clink.play();
break;
case "l":
var cymbal = new Audio('sounds/cymbal.mp3');
cymbal.play();
break;
default:
console.log(key);
}
}
function buttonPressed(key) {
var activeButton = document.querySelector("." + key);
activeButton.classList.add("pressed");
setTimeout(function() {
activeButton.classList.remove("pressed");
}, 100);
}