diff --git a/js/christmas-songs.js b/js/christmas-songs.js index 0cbec45..a6d1af9 100644 --- a/js/christmas-songs.js +++ b/js/christmas-songs.js @@ -1,46 +1,67 @@ -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); +// 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) { pauseMusic(); - }); - musicOnButton.style.display = 'none'; - }, { once: true }); + throw err; + } + }, + { once: true } + ); - audioElement.addEventListener('pause', function() { - musicOnButton.style.display = 'block'; - }); - } + // Update the AudioElement to handle pausing the song + audioElement.addEventListener("pause", function () { + musicOnButton.style.display = "block"; + musicOffButton.style.display = "none"; + }); +}; - function pauseMusic() { - audioElement.pause(); - 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 toggleMusic() { - if (audioElement.paused) { - playMusic(); - } else { - pauseMusic(); - } +// Define the toggleMusic function, handling the commands to toggle +// the buttons "musicOnButton" and "musicOffButton" +const toggleMusic = () => { + if (audioElement.paused) { + playMusic(); + } else { + pauseMusic(); } +}; - // Play music on page load - window.addEventListener('load', function() { - playMusic(); - }); \ No newline at end of file +// Play music on page load +window.addEventListener("load", () => { + playMusic(); +}); diff --git a/js/rules.js b/js/rules.js index afa4c86..cf00fd5 100644 --- a/js/rules.js +++ b/js/rules.js @@ -1,4 +1,3 @@ document.querySelector(".go-back").addEventListener("click", () => { - window.history.back(); - }); - \ No newline at end of file + window.history.back(); +}); diff --git a/js/songs.js b/js/songs.js index 35cf838..2d95876 100644 --- a/js/songs.js +++ b/js/songs.js @@ -1,53 +1,61 @@ -var songs = [ - "/music/apc.mp3", - "/music/beachvibes.mp3", - "/music/bliss.mp3", - "/music/Fluffing-a-Duck.mp3", - "/music/happyafricanvillage.mp3", - "/music/happyandjoyfulchildren.mp3", - "/music/newlands.mp3", - "/music/sotb.mp3", - "/music/tropicalfever.mp3", - "/music/tropicalsoul.mp3", - "/music/ukulele.mp3", - ]; +const songs = [ + "/music/apc.mp3", + "/music/beachvibes.mp3", + "/music/bliss.mp3", + "/music/Fluffing-a-Duck.mp3", + "/music/happyafricanvillage.mp3", + "/music/happyandjoyfulchildren.mp3", + "/music/newlands.mp3", + "/music/sotb.mp3", + "/music/tropicalfever.mp3", + "/music/tropicalsoul.mp3", + "/music/ukulele.mp3", +]; - var audioElement = document.getElementById('my_audio'); - var musicOnButton = document.getElementById('musicOnButton'); +let audioElement = document.getElementById("my_audio"); +let musicOnButton = document.getElementById("musicOnButton"); +let musicOffButton = document.getElementById("musicOffButton"); - function playMusic() { - var randomIndex = Math.floor(Math.random() * songs.length); - var audioSource = document.getElementById('audio_source'); - audioSource.src = songs[randomIndex]; - audioElement.load(); +const 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); + audioElement.addEventListener( + "canplaythrough", + () => { + audioElement.play().catch((error) => { + console.log("Error playing audio:", error); pauseMusic(); }); - musicOnButton.style.display = 'none'; - }, { once: true }); + musicOnButton.style.display = "none"; + musicOffButton.style.display = "block"; + }, + { once: true } + ); - audioElement.addEventListener('pause', function() { - musicOnButton.style.display = 'block'; - }); - } + audioElement.addEventListener("pause", () => { + musicOnButton.style.display = "block"; + musicOffButton.style.display = "none"; + }); +}; - function pauseMusic() { - audioElement.pause(); - musicOnButton.style.display = 'block'; - } +const pauseMusic = () => { + audioElement.pause(); + musicOnButton.style.display = "block"; + musicOffButton.style.display = "none"; +}; - function toggleMusic() { - if (audioElement.paused) { - playMusic(); - } else { - pauseMusic(); - } +const toggleMusic = () => { + if (audioElement.paused) { + playMusic(); + } else { + pauseMusic(); } +}; - // Play music on page load - window.addEventListener('load', function() { - playMusic(); - }); \ No newline at end of file +// Play music on page load +window.addEventListener("load", () => { + playMusic(); +}); diff --git a/js/topics.js b/js/topics.js index 7d9ad9f..44a1b24 100644 --- a/js/topics.js +++ b/js/topics.js @@ -1,8 +1,8 @@ -function toggleHidde(containerId) { +const toggleHidde = (containerId) => { // removes one & adds the other document.getElementById(containerId).classList.toggle("hide"); document.getElementById(containerId).classList.toggle("show"); -} +}; document .getElementById("technology") diff --git a/package-lock.json b/package-lock.json index 262a549..2674e90 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,3 +1,11 @@ { - "version": "8.0.1" - } + "name": "quiz", + "version": "8.0.1", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "version": "8.0.1" + } + } +} diff --git a/pages/browsers/game.html b/pages/browsers/game.html index 59c766b..3b2fc82 100644 --- a/pages/browsers/game.html +++ b/pages/browsers/game.html @@ -67,7 +67,7 @@