0
Need some help correcting this code?
I want to be able to have it so when you click the button, the <div> box will choose from an array that I assigned to a variable at random https://code.sololearn.com/Wa8uRcw9a9tp/?ref=app
2 Answers
+ 17
var colors = ["green", "blue", "red", "purple", "orange", "yellow"];
onload = function() {
button = document.getElementById("changeBox");
box = document.getElementById("dBox");
button.onclick = function() {
box.style.background = colors[Math.round(Math.random()*5)];
};
}
+ 1
thank you