I assume you're expecting your code to cause the background to rotate from red, to green, to pink, making one step every second, and then go back to pink. But what's actually happening is it's getting set to pink and then staying there, right?
That's because you have a bit of a misunderstanding of how setInterval works. Let's first look at your changeBackground function in isolation:
var color = ["red","green","pink"];
function changeBackground () {
for(var i = 0; i < color.length; i++){
document.body.style.background = color[i];
if (i == color.length) {
i = 0;
}
}
}
A couple of things to note about this: first, your conditional if (i == color.length) is never going to resolve to true. That's because the loop will only execute if i < color.length.
Second, this loop is going to execute very quickly. So quickly that it will set your background color to red, then to green, then to pink before you even notice, so all you see is a pink background. Which is exactly what's happening.
Then, you're calling this function once a second. But every time you call it, it does the exact same thing: it changes your background color so quickly you can't even see it, and then leaves it on pink.
However! I wouldn't recommend you try to do something like change the conditional to if (i == color.length - 1), because that will create an infinite loop and likely crash your browser. What you really want is to call something that changes the background color just once, and does it differently each time.