forked from KendallDoesCoding/quiz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding of points distribution (KendallDoesCoding#70)
* adding of points distribution * changes on point distribution * changes done on points distribution and bonus points * Revert "Merge branch 'main' into main" This reverts commit ef2e06f, reversing changes made to a776997. --------- Co-authored-by: Kendall <kendalldoescoding@gmail.com>
- Loading branch information
1 parent
06f0061
commit b6b11d2
Showing
33 changed files
with
719 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,46 @@ | ||
// Song URL | ||
const songs = [ | ||
"/music/christmas/AVeryMogulChristmas.mp3", | ||
"/music/christmas/FelizNavidad.mp3", | ||
"/music/christmas/DeckTheHalls.mp3", | ||
"/music/christmas/It'sThatTimeOfTheYear.mp3", | ||
]; | ||
|
||
// Initialize DOM variables | ||
let audioElement = document.getElementById("my_audio"); | ||
let musicOnButton = document.getElementById("musicOnButton"); | ||
let musicOffButton = document.getElementById("musicOffButton"); | ||
|
||
// Define the playMusic function, handling the music | ||
const playMusic = () => { | ||
// Define the song and its URL | ||
let randomIndex = Math.floor(Math.random() * songs.length); | ||
let audioSource = document.getElementById("audio_source"); | ||
|
||
// Load the song info into the audioElement | ||
audioSource.src = songs[randomIndex]; | ||
audioElement.load(); | ||
|
||
// Update the AudioElement to handle playing the song | ||
audioElement.addEventListener( | ||
"canplaythrough", | ||
() => { | ||
try { | ||
audioElement.play(); | ||
musicOnButton.style.display = "none"; | ||
musicOffButton.style.display = "block"; | ||
} catch (err) { | ||
var songs = [ | ||
"/music/christmas/AVeryMogulChristmas.mp3", | ||
"/music/christmas/FelizNavidad.mp3", | ||
"/music/christmas/DeckTheHalls.mp3", | ||
"/music/christmas/It'sThatTimeOfTheYear.mp3", | ||
]; | ||
|
||
var audioElement = document.getElementById('my_audio'); | ||
var musicOnButton = document.getElementById('musicOnButton'); | ||
|
||
function playMusic() { | ||
var randomIndex = Math.floor(Math.random() * songs.length); | ||
var audioSource = document.getElementById('audio_source'); | ||
audioSource.src = songs[randomIndex]; | ||
audioElement.load(); | ||
|
||
audioElement.addEventListener('canplaythrough', function() { | ||
audioElement.play().catch(function(error) { | ||
console.log('Error playing audio:', error); | ||
pauseMusic(); | ||
throw err; | ||
} | ||
}, | ||
{ once: true } | ||
); | ||
}); | ||
musicOnButton.style.display = 'none'; | ||
}, { once: true }); | ||
|
||
// Update the AudioElement to handle pausing the song | ||
audioElement.addEventListener("pause", function () { | ||
musicOnButton.style.display = "block"; | ||
musicOffButton.style.display = "none"; | ||
}); | ||
}; | ||
audioElement.addEventListener('pause', function() { | ||
musicOnButton.style.display = 'block'; | ||
}); | ||
} | ||
|
||
// Define the pauseMusic function, handling the commands to stop the music | ||
const pauseMusic = () => { | ||
audioElement.pause(); | ||
musicOnButton.style.display = "block"; | ||
musicOffButton.style.display = "none"; | ||
}; | ||
function pauseMusic() { | ||
audioElement.pause(); | ||
musicOnButton.style.display = 'block'; | ||
} | ||
|
||
// Define the toggleMusic function, handling the commands to toggle | ||
// the buttons "musicOnButton" and "musicOffButton" | ||
const toggleMusic = () => { | ||
if (audioElement.paused) { | ||
playMusic(); | ||
} else { | ||
pauseMusic(); | ||
function toggleMusic() { | ||
if (audioElement.paused) { | ||
playMusic(); | ||
} else { | ||
pauseMusic(); | ||
} | ||
} | ||
}; | ||
|
||
// Play music on page load | ||
window.addEventListener("load", () => { | ||
playMusic(); | ||
}); | ||
// Play music on page load | ||
window.addEventListener('load', function() { | ||
playMusic(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.