You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
546 B
25 lines
546 B
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;
|
|
})
|
|
} |