Basic Javascript algorithm for time implementation (morning, afternoon, etc.) I have a small JavaScript time detection module that detects what time it is now, like morning, afternoon, evening, or night.

How can I make the following code less redundant? Is my code already clean? It would also be great if I could get some comments on the style of the code. I really want to know what the best coding practices are.

var now = new Date(),
    hour = now.getHours();

var morning   = (hour &gt;= 4  &amp;&amp; hour &lt;= 11),
    afternoon = (hour &gt;= 12 &amp;&amp; hour &lt;= 16),
    evening   = (hour &gt;= 17 &amp;&amp; hour &lt;= 20),
    night     = (hour &gt;= 21 || hour &lt;= 3);

if(morning) {

  console.log("It's morning");

} else if(afternoon){

  console.log("It's afternoon");

} else if(evening) {

  console.log("It's evening");

} else if(night) {

  console.log("It's night");

}
The first question has to be: What is the point of this? Do you really want to (only) write the results into the console in a real application?

Other than that, it is a bit pointless to pre-calculate the conditions in variables in this case, because they are only used once and they are exclusive to each other.