-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
60 lines (53 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Drum Machine</title>
<link rel="stylesheet" href="./styles.css" />
</head>
<!-- Q, W, E, A, S, D, Z, X, C -->
<body>
<script>
function play(key) {
const audio = document.getElementById(key);
try {
audio.play();
} catch (error) {
console.log("keys: Q, W, E, A, S, D, Z, X, C\nError: ", error);
}
document.getElementById("display").innerHTML = `<h1>${key}</h1>`
}
window.document.onkeyup = event => play(event.key.toUpperCase());
</script>
<div id="drum-machine" class="container">
<h1 id="display" class="text-center text-primary">Drum Machine</h1>
<div id="display"></div>
<button class="drum-pad" id="drum-1" onclick="play('Q')"><audio id="Q" class="clip"
src="https://s3.amazonaws.com/freecodecamp/drums/Heater-1.mp3"></audio>Q</button>
<button class="drum-pad" id="drum-2" onclick="play('W')"><audio id="W" class="clip"
src="https://s3.amazonaws.com/freecodecamp/drums/Heater-2.mp3"></audio>W</button>
<button class="drum-pad" id="drum-3" onclick="play('E')"><audio id="E" class="clip"
src="https://s3.amazonaws.com/freecodecamp/drums/Heater-3.mp3"></audio>E</button>
<button class="drum-pad" id="drum-4" onclick="play('A')"><audio id="A" class="clip"
src="https://s3.amazonaws.com/freecodecamp/drums/Heater-4_1.mp3"></audio>A</button>
<button class="drum-pad" id="drum-5" onclick="play('S')"><audio id="S" class="clip"
src="https://s3.amazonaws.com/freecodecamp/drums/Heater-6.mp3"></audio>S</button>
<button class="drum-pad" id="drum-6" onclick="play('D')"><audio id="D" class="clip"
src="https://s3.amazonaws.com/freecodecamp/drums/Dsc_Oh.mp3"></audio>D</button>
<button class="drum-pad" id="drum-7" onclick="play('Z')"><audio id="Z" class="clip"
src="https://s3.amazonaws.com/freecodecamp/drums/Kick_n_Hat.mp3"></audio>Z</button>
<button class="drum-pad" id="drum-8" onclick="play('X')"><audio id="X" class="clip"
src="https://s3.amazonaws.com/freecodecamp/drums/RP4_KICK_1.mp3"></audio>X</button>
<button class="drum-pad" id="drum-9" onclick="play('C')"><audio id="C" class="clip"
src="https://s3.amazonaws.com/freecodecamp/drums/Cev_H2.mp3"></audio>C</button>
</div>
</div>
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
</body>
</html>