scrimba
#javascriptmas 21 07
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

#javascriptmas 21 07
AboutCommentsNotes
#javascriptmas 21 07
Expand for more info
index.js
run
preview
console
const playBtn = document.getElementById("play-btn")
const pauseBtn = document.getElementById("pause-btn")
const stopBtn = document.getElementById("stop-btn")
const audioFile = new Audio('./bells.mp3')

const volumeUp = document.getElementById('up')
const volumeDown = document.getElementById('down')
const volIndicator = document.getElementById('volume')
let vol = 1;
// Task:
// - Add the functionality to play, pause and stop the jingling bells (bells.mp3).

let play = () => {
audioFile.play();
}

let pause = () => {
audioFile.pause()
}

let stop = () => {
audioFile.pause()
audioFile.currentTime = 0
}

let updateVolumeIndicator = () => {
volIndicator.innerText = vol
}

let roundVolume = () => {
vol = audioFile.volume.toFixed(1)
audioFile.volume = vol


}


let volUp = () => {
if(audioFile.volume < 1) {
audioFile.volume += 0.1
} else {
audioFile.volume = 1
}

roundVolume()
updateVolumeIndicator()
}
let volDown = () => {
if(audioFile.volume > 0) {
audioFile.volume -= 0.1
} else {
audioFile.volume = 0
}

roundVolume()
updateVolumeIndicator()
}

playBtn.addEventListener('click', play)
pauseBtn.addEventListener('click', pause)
stopBtn.addEventListener('click', stop)
volumeDown.addEventListener('click', volDown)
volumeUp.addEventListener('click', volUp)


// Stretch goals:
// - Add volume controls.
// - Allow the user to select different sounds.
Console
/index.html
LIVE