I'm trying to make a static page where, if I click in any part of it, this one changes its color. I create an object with the colors hex code but I don't know how to make the document.body.style.background work with it.
Also, I would like it if the program can follow that secuence and not just throw random colors. Sorry if I look to the noob, but I'm new to programming. I'm learning by myself
It works if I put it like this:
function changeBground() {
var colors;
document.body.style.background = "#FF0000";
}
But that is only one color, is not my objective
This is my full code:
document.addEventListener("click", changeBground);
var colors = {
red: "#FF0000",
orange: "#FF7F00",
yellow: "FFFF00",
green: "#00FF00",
aqua: "#00FFFF",
blue: "#0000FF",
purple: "#8B00FF",
};
function changeBground()
{
document.body.style.background = colors;
}