scrimba
Javascriptas 2021 - Day 7 - Play a Christmas Song
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

Javascriptas 2021 - Day 7 - Play a Christmas Song
AboutCommentsNotes
Javascriptas 2021 - Day 7 - Play a Christmas Song
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 upBtn = document.getElementById("up-btn");
const downBtn = document.getElementById("down-btn");

const audio = new Audio("christmas_song.mp3");

playBtn.addEventListener("click", () => {
audio.play()
})

pauseBtn.addEventListener("click", () => {
audio.pause()
})

stopBtn.addEventListener("click", () => {
audio.pause()
audio.currentTime = 0
})

upBtn.addEventListener("click", () => {
if (audio.volume === 1) {
audio.volume = 1;
} else {
audio.volume += 0.1;
}
})

downBtn.addEventListener("click", () => {
if (audio.volume > 10) {
audio.volume = 0;
} else {
audio.volume -= 0.1;
}
})
Console
/index.html
LIVE