mardi 3 janvier 2017

playing a randomly selected piece of audio from an array, cant figure out where I went wrong

the code is as follows:

var audio1 = new Audio("sounds/sleighride.mp3");

var audio2 = new Audio("sounds/letitsnow.mp3");

var audio3 = new Audio("sounds/comingtotown.mp3");

var array = ["audio1", "audio2", "audio3"]

function soundrandom (){

var songrandom = array[Math.floor(Math.random() * array.length)];

songrandom.play(); }

soundrandom();

//end

the answer may be obvious but has had me stumped for a bit, error is "soundrandom.play(); is not a function".




Aucun commentaire:

Enregistrer un commentaire