Greeting Message to the User

This simple script that I create using JavaScript jQuery that will message the user then this program will greet the user base on the current time. Use this simple program to be polite to the user and it shows to the user how much they important in every visit to the website. Live Demo All source code construct using jQuery script. Let's construct one by one. This simple script greeting to the user for the Morning. This would be like the script.
  1. if (hours >= 5 && hours <= 11)
  2. //GREETING MESSAGE FOR MORNING
  3.     document.write('<div class="alert alert-info" role="alert"><h2>Hello! Good Morning! Have a nice day.</h2></div>')
This one, for the noon greetings to the user.
  1. if (hours == 12)
  2. //GREETING MESSAGE FOR NOON
  3.     document.write('<div class="alert alert-info" role="alert"><h2>Good Noon Visitor! </h2></div>')
And, for the afternoon greetings to the user.
  1. if (hours >= 13 && hours <= 17)
  2. //GREETING MESSAGE FOR AFTERNOON
  3.     document.write('<div class="alert alert-info" role="alert"><h2 style="color:#1982d1;">Good Afternoon! </h2></div>')
This time for the evening greetings to the user.
  1. if (hours >= 18 && hours <= 20)
  2. //MESSAGE FOR EVENING (6pm-8pm)
  3.     document.write('<div class="alert alert-info" role="alert"><h2>Good Evening! </h2></div>')
After that, this greeting would be a good night for the user.
  1. if (hours >= 21 && hours <= 11)
  2. //GREETING MESSAGE FOR NIGHT (9pm-11pm)
  3.     document.write('<div class="alert alert-info" role="alert"><h2>Good Night! </h2></div>')
Lastly, this greeting is for the user who sleeps in the late night.
  1. else
  2. //GREETING MESSAGE FOR LATE NIGHT (12pm-4am)
  3.     document.write('<div class="alert alert-info" role="alert"><h2>Wow! You`re still awake. Working Late?</h2></div>')
Complete Script
  1. <script>
  2.     var current_time = new Date()
  3.     var hours = current_time.getHours()
  4.  
  5.     if (hours >= 5 && hours <= 11)
  6.     //GREETING MESSAGE FOR MORNING
  7.         document.write('<div class="alert alert-info" role="alert"><h2>Hello! Good Morning! Have a nice day.</h2></div>')
  8.     else if (hours == 12)
  9.     //GREETING MESSAGE FOR NOON
  10.         document.write('<div class="alert alert-info" role="alert"><h2>Good Noon Visitor! </h2></div>')
  11.     else if (hours >= 13 && hours <= 17)
  12.     //GREETING MESSAGE FOR AFTERNOON
  13.         document.write('<div class="alert alert-info" role="alert"><h2 style="color:#1982d1;">Good Afternoon! </h2></div>')
  14.     else if (hours >= 18 && hours <= 20)
  15.     //MESSAGE FOR EVENING (6pm-8pm)
  16.         document.write('<div class="alert alert-info" role="alert"><h2>Good Evening! </h2></div>')
  17.     else if (hours >= 21 && hours <= 11)
  18.     //GREETING MESSAGE FOR NIGHT (9pm-11pm)
  19.         document.write('<div class="alert alert-info" role="alert"><h2>Good Night! </h2></div>')
  20.     else
  21.     //GREETING MESSAGE FOR LATE NIGHT (12pm-4am)
  22.         document.write('<div class="alert alert-info" role="alert"><h2>Wow! You`re still awake. Working Late?</h2></div>')
  23. </script>

Add new comment