What’s the best way to do a simple return function to check if it’s between 11pm and 7am?
Had something like this in mind, but the problem with this is that 1am would be 1 and that wouldn’t be greater than 23, but 23 (11pm) would be.
return (((new Date()).getHours() >= 23) && ((new Date()).getHours() <=7))
Pretty close, but you should be using || not &&
If the hours are greater or equal to 23 (11pm) OR if hours is less than or equal to 7 (7am), then true it’s between 11pm and 7am.
Noon, getHours() == 12, so then 12 >= 23 = false || 12 <= 7 = false, therefore return false;