let k = 0;
function change() {
let doc = document.body;
let color = ["black", "blue", "brown", "green"];
doc.style.backgroundColor = color[k];
k++;
if (k == color.length) {
k = 0;
}
}
setInterval(change, 1000);
**And I write **
function change2() {
let doc = document.body;
let color = ["black", "blue", "brown", "green"];
for (let r=0; r<color.length; r++){
doc.style.backgroundColor = color[r];
}
}
setInterval(change2, 1000);
First function work, but second function does not work. I do not understand this logic. Please explain me, basic logic. Please note--I am new JavaScript!