I am trying to return a random number from an array of numbers i.e. cardNumbertemp.
function cardRandomiser(){
randomCard = Math.floor(Math.random()*cardNumbertemp.length);
for (var i = 0; i < cardNumbertemp.length; i++){
if (randomCard === cardNumbertemp[i]){
cardNumbertemp.splice(i,1);
return randomCard;
}
}
}
This function needs to return a single random number from the array (cardNumbertemp) then remove the number from the array. It works however sometimes it returns undefined.