100-project-100-days-website/100_projects/47-soundboard-javascript/script.js
2023-04-09 17:40:06 +03:00
Ask

21 lines
537 B
JavaScript

{cc6de745fcd1fa71556b55d8ac75d05b9719a1f3 true 537 script.js 0xc00311cd90}

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;
});
}