Skip to content

Commit 36972da

Browse files
authored
Merge pull request #8 from itsharshpro/main
added a new drumKit project
2 parents 809611e + 55ff556 commit 36972da

File tree

18 files changed

+165
-0
lines changed

18 files changed

+165
-0
lines changed

DrumKit/.DS_Store

6 KB
Binary file not shown.

DrumKit/images/crash.png

19.1 KB
Loading

DrumKit/images/kick.png

51.9 KB
Loading

DrumKit/images/snare.png

16.8 KB
Loading

DrumKit/images/tom1.png

23.5 KB
Loading

DrumKit/images/tom2.png

22.6 KB
Loading

DrumKit/images/tom3.png

27.8 KB
Loading

DrumKit/images/tom4.png

28.5 KB
Loading

DrumKit/index.html

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

DrumKit/index.js

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

0 commit comments

Comments
 (0)