50projects50days/sound-board/script.js
2020-11-11 08:51:35 -05:00

25 lines
546 B
JavaScript

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.getElementById('buttons').appendChild(btn)
})
function stopSongs() {
sounds.forEach(sound => {
const song = document.getElementById(sound)
song.pause()
song.currentTime = 0;
})
}