Skip to content

Commit

Permalink
Final commit
Browse files Browse the repository at this point in the history
Had a small issue with the sound as it wouldn't start upon page load. I've since learned that browsers don't allow this anymore so I've had to make some adjustments to the sound toggle function. I'm happy with the project...really proud actually.
  • Loading branch information
StevieBrooks authored Jan 18, 2023
1 parent 71e5cbb commit c657231
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</div>
<section class="menu-buttons">
<button class="master-reset">Reset Game</button>
<button class="toggle-sound">Sound On / Off</button>
<button class="toggle-sound">Sound On</button>
<button class="brookscode"><a href="http://www.brookscode.com/" target="_blank">Go to <span class="but-logo">Brooks[ode</span></a></button>
</section>
</div>
Expand Down
31 changes: 23 additions & 8 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,34 @@ function playMusic() {


const toggleSound = document.querySelector('.toggle-sound');
let soundStatus = true;
toggleSound.addEventListener('click', soundOff);
function soundOff() {
soundStatus = false;
if(music.paused && music.currentTime > 0 && !music.ended) {
let soundStatus = false;
toggleSound.addEventListener('click', () => {
soundStatus = true;
if(music.currentTime == 0) {
music.play();
soundStatus = true;
} else if(music.ended) {
toggleSound.innerHTML = 'Sound Off';
} else if(music.paused && music.currentTime > 0 && !music.ended) {
music.play();
toggleSound.innerHTML = 'Sound Off';
} else {
music.pause();
soundStatus = false;
toggleSound.innerHTML = 'Sound On';
}
}
})
// let soundStatus = true;
// toggleSound.addEventListener('click', soundOff);
// function soundOff() {
// soundStatus = false;
// if(music.paused && music.currentTime > 0 && !music.ended) {
// music.play();
// soundStatus = true;
// } else if(music.ended) {
// music.play();
// } else {
// music.pause();
// }
// }

// SCOREBOX
const scoreBox = document.querySelector('.score-box');
Expand Down

0 comments on commit c657231

Please sign in to comment.