Why isn't my Audio Sounding for Simon Game?

Let’s work on one issue at a time. Do you want to work on why when the red button is clicked that the green button disappears or do you want to work on the issue you show in your console? If the latter, then what exact steps do you take to reproduce those console errors?

“Do you want to work on why when the red button is clicked that the green button disappears”
…lets work on this one first :grin:

If you turn on the game, click start, your getRandomIndex function executes. Let’s say random is equal to 1, so the following if statement evaluates to true and executes all the code inside.

        if (random == 1) {
          lightup = "hit-zero-green";
          $(".hit-zero-green").addClass(lightup);
          $("#audio1")[0].play();
          simonGamePlays.push(1);

          setTimeout(function() {
            $(".hit-zero-green").removeClass(lightup);
          }, off);
        } 

One question I have for you is why are you adding the class “hit-zero-green” to the div which already has the class “hit-zero-green”? Also, since random was one, the red sound plays and not the green, because you have forgotten that item in the buttons.item reference is zero-based.

Anyway, you play the red sound, you push the value 1 into simonGamePlays array and then you remove the “hit-zero-green” class from the div with “hit-zero-green”. When you do that, the green button disappears, because once you remove that class, the background becomes black from the parent element with class=“container”.

Hmmmmm!..let mi work through some stuff and come back to you :zipper_mouth_face: :thinking:

Looks like you guys are working through this…so I won’t jump in here and make things confusing for you @blitzkreig . Hope you all have a good day!

1 Like