50projects50days/sound-board/script.js

25 lines
546 B
JavaScript
Raw Normal View History

2020-11-11 13:51:35 +00: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.getElementById('buttons').appendChild(btn)
})
function stopSongs() {
sounds.forEach(sound => {
const song = document.getElementById(sound)
song.pause()
song.currentTime = 0;
})
}