Advertisement
RokiAdhytama

Welcome 6 - Chapter 7

Jul 2nd, 2022
1,348
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html xmlns = "http://www.w3.org/1999/xhtml">
  2.    <head>
  3.       <title>Using Relational Operators</title>
  4.  
  5.       <script type = "text/javascript">
  6.          <!--
  7.          var name; // string entered by the user
  8.             now = new Date(); // current date and time
  9.             hour = now.getHours(); // current hour (0-23)
  10.  
  11.          // read the name from the prompt box as a string
  12.          name = window.prompt( "Please enter your name", "GalAnt" );
  13.  
  14.          // determine whether it is morning
  15.          if ( hour < 12 )
  16.             document.write( "<h1>Good Morning, " );
  17.  
  18.          // determine whether the time is PM
  19.          if ( hour >= 12 )
  20.          {
  21.             // convert to a 12 hour clock
  22.             hour = hour - 12;
  23.  
  24.             // determine whether it is before 6 PM
  25.             if ( hour < 6 )
  26.                document.write( "<h1>Good Afternoon, " );
  27.  
  28.             // determine whether it is after 6 PM
  29.             if ( hour >= 6 )
  30.                document.write( "<h1>Good Evening, " );
  31.          }
  32.  
  33.          document.writeln( name +
  34.             ", welcome to JavaScript programming!</h1>" );
  35.          // -->
  36.       </script>
  37.  
  38.    </head>
  39.  
  40.    <body>
  41.       <p>Click Refresh (or Reload) to run this script again.</p>
  42.    </body>
  43. </html>
Advertisement
RAW Paste Data Copied
Advertisement