Simon game audio bug

Hi guys, I have a small problem. I wrote a function that plays the sound when you click on a specific “pad” on the game, my problem is that the sound for each pad only plays on the first time I click on the pads, when I click on the pad again there is no sound, any idea why this is happening?

  var soundRed = $("#sound-red")[0];
  var soundBlue = $("#sound-blue")[0];
  var soundYellow = $("#sound-yellow")[0];
  var soundGreen = $("#sound-green")[0];  

 $(".pad").on("click", function(){

    if ( === "0") {;
    } else if ( === "1") {;
    } else if ( === "2") {; 
    } else if ( === "3") {; 

codepen link:

It works for me. A sound plays when pressing each pad.

You could use the load method before the play method, like:


If you changed your audio element ids to the following: sound-0, sound-1, sound-2, sound-3, then you could simplify your pad click event as follows:

  $(".pad").on("click", function() {
    var $sound = $('#sound-' +;
1 Like

Thanks for the tip, will try that out!