21 lines
537 B
JavaScript
21 lines
537 B
JavaScript
{cc6de745fcd1fa71556b55d8ac75d05b9719a1f3 true 537 script.js 0xc002b147e0}
const sounds = ["applause", "boo", "gasp", "tada", "victory", "wrong"];
|
|
|
|
sounds.forEach((sound) => {
|
|
const btn = document.createElement("button");
|
|
btn.classList.add("btn");
|
|
btn.innerText = sound;
|
|
|
|
btn.addEventListener("click", () => {
|
|
stopSongs();
|
|
|
|
document.getElementById(sound).play();
|
|
});
|
|
document.body.appendChild(btn);
|
|
});
|
|
function stopSongs() {
|
|
sounds.forEach((sound) => {
|
|
const song = document.getElementById(sound);
|
|
song.pause();
|
|
song.currentTime = 0;
|
|
});
|
|
} |