I've been trying to come up with the most concise way that I can possibly change background colors using JavaScript. (Trying to get the hang of forEach and higher order functions just for fun.) Anyway, this will run on page load, and I think I'm pretty close:
function background(){ var colorArray = ["#14183b", "#002e2e", "#0d2d40", "#173052", "#194759", "#296b73"]; function change(newcolor){ document.body.style.backgroundColor=newcolor; } colorArray.forEach(function(color){ setTimeout(change(color), 1000); }); } The problem is that the background color is only showing the last element in the array. I also am not sure how to start the forEach loop over again when it is has finished. Thanks for any help!