Greeting message according to time

Posted by Abhisek under JavaScript category on | Views : 10656
The following javascript will display greeting message like, Good Morning, Good Afternoon and Good Evening according to the time.

currentTime=new Date();
//getHour() function will retrieve the hour from current time
document.write("Good Morning");
else if(currentTime.getHours()<17)
document.write("Good Afternoon");
document.write("Good Evening");
//End of JavaScript functions

It will display 'Good Morning' if you run it between 12o'clock. After 12o'clock till 5pm it will display 'Good Afternoon' and after 5pm it will display 'Good Evening' on the web browser. You can embed this code in your webpage to greet a user according to time automatically.

Comments or Responses

Login to post response