jeudi 15 décembre 2016

choose random array and then an element from this array

I'm trying to figure out if it's possible to first choose a random array (on load) and then an element from this chosen array. So for example I have:

    var colorsOne = ["#CCCCCC","#333333","#990099","#990099"];  
    var colorsTwo = ["#CCCCCC","#333333","#990099","#990099"];  
    var colorsThree = ["#CCCCCC","#333333","#990099","#990099"];  
    var colorsFour = ["#CCCCCC","#333333","#990099","#990099"];  
    var colorsFive = ["#CCCCCC","#333333","#990099","#990099"];  
    var colorsSix = ["#CCCCCC","#333333","#990099","#990099"];  
    var colorsSeven = ["#CCCCCC","#333333","#990099","#990099"];  
    var colorsEight = ["#CCCCCC","#333333","#990099","#990099"];  
    var colorsNine = ["#CCCCCC","#333333","#990099","#990099"];  
    var colorsTen = ["#CCCCCC","#333333","#990099","#990099"];  
    var colorsEleven = ["#CCCCCC","#333333","#990099","#990099"];  
    var colorsTwelve = ["#CCCCCC","#333333","#990099","#990099"];  

12 arrays (each one will eventually be populated with different hex codes), I first need to choose one of these array and then one hex code (at random) from this array.

e.g.

var rand = Math.floor(Math.random() * 4);               
$('.header-wrap').css("background-color", colorsEight[rand]);

this will take a random element from coloursEight array, but I've had to program that, I need to choose an array randomly first and THEN choose an element from this array.

Any suggestions for this would be greatly appreciated!




Aucun commentaire:

Enregistrer un commentaire