Time of the Day Greeting Message in Javascript

Language

In this tutorial we are going to learn how to display a greetings message according to the time of the day. Here's the little javascript code that will display the messages. Copy the code and paste it to your body section. You change the messages below to what you want.
  1. <script>
  2. var Digital=new Date()
  3. var hours=Digital.getHours()
  4.  
  5. if (hours>=5&&hours<=11)
  6. //GREETING MESSAGE FOR MORNING
  7. document.write('<h2>Hello! Good Morning! Have a nice day.</h2>')
  8. else if (hours==12)
  9. //GREETING MESSAGE FOR NOON
  10. document.write('<h2>Good Noon Visitor! </h2>')
  11. else if (hours>=13&&hours<=17)
  12. //GREETING MESSAGE FOR AFTERNOON
  13. document.write('<h2>Good Afternoon! </h2>')
  14. else if (hours>=18&&hours<=20)
  15. //MESSAGE FOR EVENING (6pm-8pm)
  16. document.write('<h2>Good Evening! </h2>')
  17. else if (hours>=21&&hours<=11)
  18. //GREETING MESSAGE FOR NIGHT (9pm-11pm)
  19. document.write('<h2>Good Night! </h2>')
  20. else
  21. //GREETING MESSAGE FOR LATE NIGHT (12pm-4am)
  22. document.write('<h2>Wow! You`re still awake. Working Late?</h2>')
  23.  
  24. </script>

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment