Home › Forums › JavaScript › Change Body Background Every 10 sec › Reply To: Change Body Background Every 10 sec
January 4, 2019 at 2:21 am
#280907
sagarleo1
Participant
Hii, I have given you the code (JavaScript), try it yourself and share the result
var i = 0;
function change() {
var doc = document.getElementById(“background”);
var color = [“black”, “blue”, “brown”, “green”];
doc.style.backgroundColor = color[i];
i = (i + 1) % color.length;
}
setInterval(change, 1000);