-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
106 lines (106 loc) · 2.89 KB
/
index.html
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!doctype html>
<html>
<head>
<title>i was starting to get bored</title>
<style>
.drum-pad {
width: 4em;
height: 4em;
text-align: center;
background-color: black;
color: white;
padding: 1em;
background-clip: content-box;
}
#drum-machine {
display: flex;
width: 20em;
flex-wrap: wrap;
}
#display {
width: 20em;
background-color: blue;
color: white;
text-align: center;
height: 2em;
}
</style>
<script>
function init() {
Array.from(document.getElementsByClassName("drum-pad")).forEach(function (element) {
element.onclick = function(e) {
e.target.children[0].currentTime = 0;
e.target.children[0].play();
updateDisplay(e.target.children[0].id)
}
})
document.body.onkeypress = function(e) {
try {
let target = document.getElementById(e.key.toUpperCase())
target.currentTime = 0
target.play()
updateDisplay(target.id)
} catch {
}
}
return true;
}
function updateDisplay(character) {
let display = document.getElementById("display");
switch(character) {
case "Q": {
display.innerText = `Make the Q's!`;
break;
}
case "W": {
display.innerText = `W for Winning!`;
break;
}
case "E": {
display.innerText = `Electronic!`;
break;
}
case "A": {
display.innerText = `Awesome!`;
break;
}
case "S": {
display.innerText = `Send the charts flying!`;
break;
}
case "D": {
display.innerText = `Do the double!`;
break;
}
case "Z": {
display.innerText = `Funky Zebra!`;
break;
}
case "X": {
display.innerText = `X-treme!`;
break;
}
case "C": {
display.innerText = `Cool!`;
break;
}
}
}
</script>
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js" async ></script>
</head>
<body onload="init()">
<div id="drum-machine">
<div class="drum-pad">Q<audio src="Q.mp3" class="clip" id="Q" preload="auto"></audio></div>
<div class="drum-pad">W<audio src="W.mp3" class="clip" id="W" preload="auto"></audio></div>
<div class="drum-pad">E<audio src="E.mp3" class="clip" id="E" preload="auto"></audio></div>
<div class="drum-pad">A<audio src="A.mp3" class="clip" id="A" preload="auto"></audio></div>
<div class="drum-pad">S<audio src="S.mp3" class="clip" id="S" preload="auto"></audio></div>
<div class="drum-pad">D<audio src="D.mp3" class="clip" id="D" preload="auto"></audio></div>
<div class="drum-pad">Z<audio src="Z.mp3" class="clip" id="Z" preload="auto"></audio></div>
<div class="drum-pad">X<audio src="X.mp3" class="clip" id="X" preload="auto"></audio></div>
<div class="drum-pad">C<audio src="C.mp3" class="clip" id="C" preload="auto"></audio></div>
<div id="display">drum machine thing</div>
</div>
</body>
</html>