-
-
Notifications
You must be signed in to change notification settings - Fork 678
Expand file tree
/
Copy pathscript.js
More file actions
21 lines (19 loc) · 577 Bytes
/
script.js
File metadata and controls
21 lines (19 loc) · 577 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const sounds = ["applause", "boo", "gasp", "tada", "victory", "wrong"];
const buttons = document.getElementById("buttons");
const stopSounds = () => {
sounds.forEach((sound) => {
const currentSound = document.getElementById(sound);
currentSound.pause();
currentSound.currentTime = 0;
});
};
sounds.forEach((sound) => {
const btn = document.createElement("button");
btn.classList.add("btn");
btn.innerText = sound;
btn.addEventListener("click", () => {
stopSounds();
document.getElementById(sound).play();
});
buttons.appendChild(btn);
});