dimanche 15 novembre 2020

Play a random song on button press using Javascript

I made some HTML code a function so that when a button is clicked it runs randomSong() which is supposed to run a random song right now it runs this

             function randomSong() {
                var n = (1 + Math.random() * 2);
                if (n ==enter code here 0){
                    var song = document.getElementById('1')
                    console.log("0")
                }else if(n == 1){
                    var song = document.getElementById('2');
                    console.log('1')}
              let y = song
                }
        var x = y

        function playAudio() {
          x.play();
        }

        function pauseAudio() {
          x.pause();
        }

but it doesn't work it says x is not defined anyone now why? Link to the website I am using this for




Aucun commentaire:

Enregistrer un commentaire