I have an array ['green', 'red', 'yellow', 'blue'].
I want to change the background color of my website using these colors. But I don't want to just take a random color from this array. I want to iterate it in order.
So if I get the background color of my website with getBgColor() and it prints red, then I want a function setBgColor(currentColor) to print yellow. How do I do this?
I guess I should do something like
function setBgColor(currentColor) {
var array = ['green', 'red', 'yellow', 'blue'];
newColor = array[array.indexOf(currentColor) + 1];
}
but is this the right approach? And how do I make sure that I go from blue to green and thus not exceeding the length of the array?