Question:

How to greet website visitors accordingly to the time using HTML or Javascript?

by  |  earlier

0 LIKES UnLike

such as good morning during AM hours

good afternoon during NOON

and good evening during PMs

thanks

 Tags:

   Report

2 ANSWERS


  1. http://www.quackit.com/javascript/javasc...

    That will give you how to find the date / time.  Then once you get the hour if it's between 00 - 12 (it's morning), 12-16 (it's afternoon), 16-24 (it's evening)

    Take care,

    Chad


  2.    <head>

          <title>Using Relational Operators</title>

          <script type = "text/javascript">

             <!--

             var name; // string entered by the user

             var now = new Date(); // current date and time

             var hour = now.getHours(); // current hour (0-23)

             // read the name from the prompt box as a string

             name = window.prompt( "Please enter your name" );

             // determine whether it is morning

             if ( hour < 12 )

                document.write( "<h1>Good Morning, " );

             // determine whether the time is PM

             if ( hour >= 12 )

             {

                // convert to a 12-hour clock

                hour = hour - 12;

                // determine whether it is before 6 PM

                if ( hour < 6 )

                   document.write( "<h1>Good Afternoon, " );

                // determine whether it is after 6 PM

                if ( hour >= 6 )

                   document.write( "<h1>Good Evening, " );

             } // end if

             document.writeln( name +

                ", welcome to JavaScript programming!</h1>" );

             // -->

          </script>

       </head>

       <body>

          <p>Click Refresh (or Reload) to run this script again.</p>

       </body>

    </html>

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.