100-project-100-days-website/100_projects/47-soundboard-javascript/script.js

21 lines
537 B
JavaScript
Raw Normal View History

2023-04-09 17:40:06 +03:00
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;
});
}