Q:

Javascript if statement returning wrong value

var checkHour = new Date();
checkHour.getHours();

If statement inside time() function seems to be returning Good Evening.  At this present time it should be returning good morning.  What am I doing wrong? 
function time(){
    if((checkHour >= 0) && (checkHour <= 12)){
alert(" Good Morning");
    }else if((checkHour >= 12) && (checkHour <= 18)){
alert("Afternoon");
    }else{
      alert("Good Evening")
    }
}

time();

A:

It looks like your checkHour variable is loaded with the date.   You never set it's value to the hours. 
Perhaps you meant the second line to read: checkHour = checkHour.getHours();, so your corrected code would be:
var checkHour = new Date();
checkHour = checkHour.getHours();

function time(){
    if((checkHour >= 0) && (checkHour <= 12)){
    alert(" Good Morning");
    }else if((checkHour >= 12) && (checkHour <= 18)){
        alert("Afternoon");
    }else{
      alert("Good Evening")
    }
}

