How would I give a variable a random value in javascript?
I can do this:
var myMake = ["Chevy","Subaru","Kia","Honda","Toyota"];
var x = Math.floor(Math.random() * 4 + 1);
var rand = myMake[x];
alert(rand);
which gets the desired effect, giving the variable rand
a random value of one of these:
Chevy, Subaru, Kia, Honda, Toyota
but would there be a way to make a function/method that does something like this?:
var rand = randVal("Chevy", "Subaru", "Kia", "Honda", "Toyota");
Thanks!!