dimanche 30 mai 2021

Audio.play() doesn't work ONLY in if statement

So I am making a small game to practice javascript. I wanted to add the getting point sound when the car is not crashing with the obstacle. If car is not crashing with obstacle I am adding points and making that the obstacle disappears and appearing once again in the top of the road so everything is working just fine. Under those lines I added the audio.play(); function and it is not working. I added the alert to check if it should work and alert is appearing so what is going on?

else if(document.getElementById("B7").innerHTML == '<div id="obstacle">X</div>' || document.getElementById("A7").innerHTML == '<div id="obstacle">X</div>')
        {
            document.getElementById("A7").innerHTML = "";
            document.getElementById("B7").innerHTML = "";
            points = points + addPoints;
            audio.play();
            alert("sound here");
            nextObstacle();
        }

Link for GitHub repository for this project:

https://github.com/AdamMaichrzik/Spliterio/blob/master/car.html

Lines 270 - 280.

Aucun commentaire:

Enregistrer un commentaire