Member Avatar
exonwarrior

Hey all! I have to come up with code for taking the contents of an input box on my webpage, use that as the name in my script and then display a message based on the time, say "Good morning Dave!" if it's between 5am and 12pm. I have all the code, and yet it doesn't work.

function greetingMessage(){
         var d = new Date();
         var time = d.getHours();

         name = document.forms[0].inputNameTextBox.value;

         if (time >= 22 && time < 5) {
            alert("Good Night, " + name)
         } else if (time >= 5 && time < 12) {
            alert("Good Morning, " + name)
         } else if (time >= 12 && time < 17) {
            alert("Good Afternoon, " + name)
         } else if (time >= 17 && time < 22) {
            alert("Good Evening, " + name)
         }
         else {
            alert("I'm really confused, I don't know what time it is! :(")
         }

         document.getElementById('inputNameTextBox').value = '';
}

However, this doesn't work, it always displays the final alert....
Any help much appreciated!

Dave