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

17th Dec 2017, 9:01 PM
Jesse Douglas
Jesse Douglas - avatar
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)]; }; }
17th Dec 2017, 9:20 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
thank you
17th Dec 2017, 9:36 PM
Jesse Douglas
Jesse Douglas - avatar