-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
72 lines (70 loc) · 2.33 KB
/
main.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
70
71
72
function press(event){
console.log("The '" +event.key+"' key is pressed.");
}
document.addEventListener("keydown",function(event){
if(event.code === "KeyA") {
press(event);
let audio = document.createElement("AUDIO");
audio.src = "white_keys/A.mp3";
audio.play();
} else if(event.code === "KeyS") {
press(event);
let audio = document.createElement("AUDIO");
audio.src = "white_keys/S.mp3";
audio.play();
} else if(event.code === "KeyD") {
press(event);
let audio = document.createElement("AUDIO");
audio.src = "white_keys/D.mp3";
audio.play();
} else if(event.code === "KeyF") {
press(event);
let audio = document.createElement("AUDIO");
audio.src = "white_keys/F.mp3";
audio.play();
} else if(event.code === "KeyG") {
press(event);
let audio = document.createElement("AUDIO");
audio.src = "white_keys/G.mp3";
audio.play();
} else if(event.code === "KeyH") {
press(event);
let audio = document.createElement("AUDIO");
audio.src = "white_keys/H.mp3";
audio.play();
} else if(event.code === "KeyJ") {
press(event);
let audio = document.createElement("AUDIO");
audio.src = "white_keys/J.mp3";
audio.play();
}
//BLACK KEYS
else if(event.code === "KeyW") {
press(event);
let audio = document.createElement("AUDIO");
audio.src = "black_keys/W.mp3";
audio.play();
} else if(event.code === "KeyE") {
press(event);
let audio = document.createElement("AUDIO");
audio.src = "black_keys/E.mp3";
audio.play();
} else if(event.code === "KeyT") {
press(event);
let audio = document.createElement("AUDIO");
audio.src = "black_keys/T.mp3";
audio.play();
} else if(event.code === "KeyY") {
press(event);
let audio = document.createElement("AUDIO");
audio.src = "black_keys/Y.mp3";
audio.play();
} else if(event.code === "KeyU") {
press(event);
let audio = document.createElement("AUDIO");
audio.src = "black_keys/U.mp3";
audio.play();
} else {
console.log("Error")
}
});