Domanda

I'm having the strangest problem right now; This if-statement below should run the console.log("It's night!") when the currentHour is between 22 and 07, but for some reason it doesn't!

console.log("hello");
console.log(currentHour);
if (currentHour >= 22 && currentHour <= 7) {console.log("Its night!");};

Console output:

hello
22

So the if-statement is not run.

È stato utile?

Soluzione

If current hour is HIGHER/equal than 22 AND LOWER/equal than seven will never be true.

What you probably want:

if(currentHour >= 22 || currentHour <=7)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top