Random element of the array with JavaScript


function random(range) {

	return Math.floor(Math.random() * range);

}

var colours = ['red', 'orange', 'yellow', 'green', 'blue'];

var color = colours[random(5)];

Leave a Comment