-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (56 loc) · 1.2 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
63
64
65
66
67
68
69
var numberofbuttons=document.querySelectorAll(".drum" ).length;
for(var i=0;i<numberofbuttons;i++)
{
document.querySelectorAll(".drum")[i].addEventListener("click",function ()
{
var buttonInnerHtml= this.innerHtml;
makesound(buttonInnerHtml);
});
}
//press key
document.addEventListener("keypress",function(event)
{
makesound(event.key);
});
function makesound(key)
{
switch (key) {
case "a":
var clap= new Audio("sounds/clap.wav");
clap.play();
break;
case "s":
var snare=new Audio("sounds/hihat.wav");
snare.play();
break;
case "d":
var kick=new Audio("sounds/kick.wav");
kick.play();
break;
case "f":
var openhat=new Audio("sounds/openhat.wav");
openhat.play();
break;
case "g":
var boom=new Audio("sounds/boom.wav");
boom.play();
break;
case "h":
var ride=new Audio("sounds/ride.wav");
ride.play();
break;
case "j":
var snare=new Audio("sounds/snare.wav");
snare.play();
break;
case "k":
var tom=new Audio("sounds/tom.wav");
tom.play();
break;
case "l":
var tink=new Audio("sounds/tink.wav");
tink.play();
break;
default:console.log("rr");
}
};