I am new to javascript so sorry in advance for the simplicity of this question.
On load of the web page I would like my div to be a random colour denoted in my array.
HTML
body onload="start"()"
JS
var color = ["red", "blue", "yellow", "green"];
function start() {
document.getElementById("sq").style.backgroundColor = color[Math.floor(Math.random() * color.length)];
}
My apologies, I cannot get the random color set to the div. I tried to set a color directly i.e. blue. and that worked. but using the array does not at all.
So finally, I would like my div to be a random color out of my array every time I start the web page