samedi 11 mai 2019

i try to change the color of the background by using the current time

i try to run my code but it does not work

i already tried to use a "color" variable,using rgb(x,x,x) codes,#xxxx,without quotation marks...

var thehours = new Date().getHours();
if (thehours >= 0 && thehours < 12) {
     document.body.style.backgroundColor = "white";
} else if (thehours >= 12 && thehours < 18) {
    document.body.style.backgroundColor = "grey";
} else if (thehours >= 18 && thehours < 24) {
    document.body.style.backgroundColor = "black";  
}

in console i get this "Uncaught TypeError: Cannot read property 'style' of null at design.js:3"




Aucun commentaire:

Enregistrer un commentaire