Advertisement
RokiAdhytama

Final - Chapter 12-1

Jul 4th, 2022
1,498
0
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>Putting It All Together</title>
  4.  
  5.       <script type = "text/javascript">
  6.          <!--
  7.          var now = new Date(); // current date and time
  8.          var hour = now.getHours(); // current hour
  9.  
  10.          // array with names of the images that will be randomly selected
  11.          var pictures =
  12.             [ "CPE", "EPT", "GPP", "GUI", "PERF", "PORT", "SEO" ];
  13.  
  14.          // array with the quotes that will be randomly selected
  15.          var quotes = [ "Form ever follows function.<br/>" +
  16.             " Louis Henri Sullivan", "E pluribus unum." +
  17.             " (One composed of many.) <br/> Virgil", "Is it a" +
  18.             " world to hide virtues in?<br/> William Shakespeare" ];
  19.  
  20.          // write the current date and time to the web page
  21.          document.write( "<p>" + now.toLocaleString() + "<br/></p>" );
  22.  
  23.          // determine whether it is morning
  24.          if ( hour < 12 )
  25.             document.write( "<h2>Good Morning, " );
  26.          else
  27.          {
  28.             hour = hour - 12; // convert from 24 hour clock to PM time
  29.  
  30.             // determine whether it is afternoon or evening
  31.             if ( hour < 6 )
  32.                document.write( "<h2>Good Afternoon, " );
  33.             else
  34.                document.write( "<h2>Good Evening, " );
  35.          }
  36.  
  37.          // determine whether or not there is a cookie
  38.          if ( document.cookie )
  39.          {
  40.             // convert escape characters in the cookie string to their
  41.             // english notation
  42.             var myCookie = unescape( document.cookie );
  43.  
  44.             // split the cookie into tokens using = as delimiter
  45.             var cookieTokens = myCookie.split( "=" );
  46.  
  47.             // set name to the part of the cookie that follows the = sign
  48.             name = cookieTokens[ 1 ];
  49.          }
  50.          else
  51.          {
  52.             // if there was no cookie then ask the user to input a name
  53.             name = window.prompt( "Please enter your name", "GalAnt" );
  54.  
  55.             // escape non-alphanumeric characters in the name string
  56.             // and add name to the cookie
  57.             document.cookie = "name=" + escape( name );
  58.          }
  59.  
  60.          // write the greeting to the page
  61.          document.writeln(
  62.             name + ", welcome to JavaScript programming!</h2>" );
  63.  
  64.          // write the link for deleting the cookie to the page
  65.          document.writeln( "<a href = \" JavaScript:wrongPerson() \" > " +
  66.             "Click here if you are not " + name + "</a><br/>" );
  67.  
  68.          // write the random image to the page
  69.          document.write ( "<img src = \"" +
  70.             pictures[ Math.floor( Math.random() * 7 ) ] +
  71.             ".gif\" width= \" 105 \" height= \" 100 \" /> <br/>" );
  72.  
  73.          // write the random quote to the page
  74.          document.write ( quotes[ Math.floor( Math.random() * 3 ) ] );
  75.  
  76.          // create a window with all the quotes in it
  77.          function allQuotes()
  78.          {
  79.             // create the child window for the quotes
  80.             quoteWindow = window.open( "", "", "resizable=yes, toolbar" +
  81.                "=no, menubar=no, status=no, location=no," +
  82.                " scrollBars=yes" );
  83.             quoteWindow.document.write( "<p>" )
  84.  
  85.             // loop through all quotes and write them in the new window
  86.             for ( var i = 0; i < quotes.length; i++ )
  87.                quoteWindow.document.write( ( i + 1 ) + ".) " +
  88.                   quotes[ i ] + "<br/><br/>");
  89.  
  90.             // write a close link to the new window
  91.             quoteWindow.document.write( "</p><br/><a href = \" " +
  92.                "JavaScript:window.close()\">" +
  93.                " Close this window </a>" )
  94.          }
  95.  
  96.          // reset the document's cookie if wrong person
  97.          function wrongPerson()
  98.          {
  99.             // reset the cookie
  100.             document.cookie= "name=null;" +
  101.                " expires=Thu, 01-Jan-95 00:00:01 GMT";
  102.  
  103.             // after removing the cookie reload the page to get a new name
  104.             location.reload();
  105.          }
  106.  
  107.          // open a new window with the quiz2.html file in it
  108.          function openQuiz()
  109.          {
  110.             window.open( "quiz2.html", "", "resizable = yes, "+
  111.                "toolbar = no, menubar = no, status = no, " +
  112.                "location = no, scrollBars = no");
  113.          }
  114.       // -->
  115.       </script>
  116.  
  117.    </head>
  118.  
  119.    <body>
  120.       <p><a href = "JavaScript:allQuotes()">View all quotes</a></p>
  121.  
  122.       <p id = "quizSpot">
  123.          <a href = "JavaScript:openQuiz()">Please take our quiz</a></p>
  124.  
  125.       <script type = "text/javascript">
  126.          // variable that gets the last midification date and time
  127.          var modDate = new Date( document.lastModified );
  128.  
  129.          // write the last modified date and time to the page
  130.          document.write ( "This page was last modified " +
  131.             modDate.toLocaleString() );
  132.       </script>
  133.  
  134.    </body>
  135. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement