jeudi 8 février 2018

How to link many variables to one array and select it's elements ramdonly?

Let's say I'm making some system where I combine colors to feelings and other concepts, like "happiness", "mad" or "money". The first thing that comes to my mind is an array. So each keywork will represent a list of colors that matches with it, like:

let happy = ['#00ffff', '#ea3575', '#ffea6c', '#ff9a55']

But there's an issue: many different keywords has the same color matches, like 'money' + 'rich', or 'sad' + 'sadness', so I'd have to declare many variables to one array of many colors. That's the part I don't know what to do.

Also, if I want the body of the page to be painted by a randomly selected color at happy's array, do you think would it be like this? Here:

function paintBody() {
document.body.style.background = happy[Math.floor(Math.random() * 4)];
}




Aucun commentaire:

Enregistrer un commentaire