Skip to content

Commit 9c3b709

Browse files
authored
Merge pull request #3 from chandankumar1307/main
Added a drum kit project
2 parents 966690a + dd88cc2 commit 9c3b709

File tree

18 files changed

+169
-0
lines changed

18 files changed

+169
-0
lines changed

Drum Kit Starting Files/.DS_Store

6 KB
Binary file not shown.
19.1 KB
Loading
51.9 KB
Loading
16.8 KB
Loading
23.5 KB
Loading
22.6 KB
Loading
27.8 KB
Loading
28.5 KB
Loading

Drum Kit Starting Files/index.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html lang="en" dir="ltr">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Drum Kit</title>
7+
<link rel="stylesheet" href="styles.css">
8+
<link href="https://fonts.googleapis.com/css?family=Arvo" rel="stylesheet">
9+
</head>
10+
11+
<body>
12+
13+
<h1 id="title">Drum 🥁 Kit</h1>
14+
<div class="set">
15+
<button class="w drum">w</button>
16+
<button class="a drum">a</button>
17+
<button class="s drum">s</button>
18+
<button class="d drum">d</button>
19+
<button class="j drum">j</button>
20+
<button class="k drum">k</button>
21+
<button class="l drum">l</button>
22+
</div>
23+
24+
25+
<footer>
26+
Made with ❤️ in London.
27+
<script src="index.js" charset="utf-8"></script>
28+
</footer>
29+
</body>
30+
31+
</html>

Drum Kit Starting Files/index.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
var numberOfDrums=document.querySelectorAll(".drum").length;
3+
for(var i=0;i<numberOfDrums;i++){
4+
document.querySelectorAll(".drum")[i].addEventListener("click", function(){
5+
var h=this.innerHTML;
6+
check(h);
7+
buttonAnimation(h);
8+
});
9+
10+
}
11+
document.addEventListener("keydown", function(event){
12+
check(event.key);
13+
buttonAnimation(event.key);
14+
});
15+
16+
function check(b){
17+
switch (b) {
18+
case "w":
19+
var voice=new Audio("sounds/crash.mp3");
20+
voice.play();
21+
break;
22+
case "a":
23+
var voice=new Audio("sounds/kick-bass.mp3");
24+
voice.play();
25+
break;
26+
case "s":
27+
var voice=new Audio("sounds/snare.mp3");
28+
voice.play();
29+
break;
30+
case "d":
31+
var voice=new Audio("sounds/tom-1.mp3");
32+
voice.play();
33+
break;
34+
case "j":
35+
var voice=new Audio("sounds/tom-2.mp3");
36+
voice.play();
37+
break;
38+
case "k":
39+
var voice=new Audio("sounds/tom-3.mp3");
40+
voice.play();
41+
break;
42+
case "l":
43+
var voice=new Audio("sounds/tom-4.mp3");
44+
voice.play();
45+
default:
46+
alert("Wrong Key");
47+
}
48+
}
49+
50+
function buttonAnimation(currentKey){
51+
var activeButton=document.querySelector("."+currentKey);
52+
activeButton.classList.add("pressed");
53+
54+
setTimeout(function(){
55+
activeButton.classList.remove("pressed")
56+
},100);
57+
}

0 commit comments

Comments
 (0)