How to change just the div background-color and not the entirely body-color?

code

Currently bstyle is assigned body.style, so when you write:

bstyle.backgroundColor = "green";

you are changing the background of the body and not the hello div.

Another way to reduce repetition in your code would be to do the following. Only click on the blurred section if you want to see a working solution.

function updateBackground() {
  var 
    hr = (new Date()).getHours(),
    hello = document.querySelector(".hello");  
  
  var divBg = hr < 10 
    ? ['yellow', 'black', 'Have a good morning']
    : hr < 20
      ? ['green', 'white', 'Have a good day']
      : ['black', 'white', 'Have a good night']
  
  var [bg, color, text] = divBg;
  hello.style.backgroundColor = bg;
  hello.style.color = color;
  hello.innerText = text; 
}

setInterval(updateBackground, 1000 * 60);
updateBackground();