So my main goal is to randomize background every 1 second after clicking button. The problem is I'm getting random RGB every second as my console outputs it, but the background changes only after the last iteration.
function random_background(){
var i;
for(i = 0; i < 3; i++){
let red = Math.floor(Math.random() * 256);
let green = Math.floor(Math.random() * 256);
let blue = Math.floor(Math.random() * 256);
let randomcolor = "rgb(" + red + "," + green + "," + blue + ")";
console.log(randomcolor);
document.body.style.background = randomcolor;
sleep(1000);
}
}