vendredi 13 mai 2016

Selecting random array elements and placing into another

I have an array of strings and require just 4 of these (randomly) to be placed into another array.

var a = ["Orange", "Red", "Yellow", "Blue", "Black", "White", "Brown", "Green"];
var b = [];
function selectColours(){
    var toRandomise = a[Math.floor(Math.random() * 4)];
    b.push(toRandomise);
}
console.log(b);

My problem is that the Console shows nothing appearing.




Aucun commentaire:

Enregistrer un commentaire