Wednesday, July 10, 2013

How To Show Different Greetings at Different Times During The Day Using Javascript

0 comments
To show different greetings for different times of day we use if else loop.here is a example which help you to sow different greetings of the day.

<HTML><HEAD><TITLE>Examples of using a Date object and the if and if else statements.</TITLE></HEAD><BODY><PRE> This script provides examples of using the Date object to obtain the hour of the day. The hour is used to print different messages at different times during the day. 
<SCRIPT Language="JavaScript"> 
now = new Date()                 //create a Date object named: now
hour = now.getHours()         //hours range from 0 to 23.
                                           //0 is midnight to before 1 AM.  
noon = 12                          //Afternoon begins at noon.
evening = 18                     //Evening begins at 6 PM.
if (hour < noon)
document.writeln("Good Morning.")
else if (hour < evening)
document.writeln("Good Afternoon.")
else
document.writeln("Good Evening.")
</SCRIPT>
</PRE>
</BODY>
</HTML>

OUTPUT :This script provides examples of using the Date object to obtain the hour of the day. The hour is used to print different messages at different times during the day.
Good Evening.
NOTE: Here the msg is shown good evening because hour>afternoon i.e. the third loop is used.

Leave a Reply

 
How To 99 © 2013 How to 99 &

How to Tutorial in 99 Categories