Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html xmlns = "http://www.w3.org/1999/xhtml">
- <head>
- <title>Putting It All Together</title>
- <script type = "text/javascript">
- <!--
- var now = new Date(); // current date and time
- var hour = now.getHours(); // current hour
- // array with names of the images that will be randomly selected
- var pictures =
- [ "CPE", "EPT", "GPP", "GUI", "PERF", "PORT", "SEO" ];
- // array with the quotes that will be randomly selected
- var quotes = [ "Form ever follows function.<br/>" +
- " Louis Henri Sullivan", "E pluribus unum." +
- " (One composed of many.) <br/> Virgil", "Is it a" +
- " world to hide virtues in?<br/> William Shakespeare" ];
- // write the current date and time to the web page
- document.write( "<p>" + now.toLocaleString() + "<br/></p>" );
- // determine whether it is morning
- if ( hour < 12 )
- document.write( "<h2>Good Morning, " );
- else
- {
- hour = hour - 12; // convert from 24 hour clock to PM time
- // determine whether it is afternoon or evening
- if ( hour < 6 )
- document.write( "<h2>Good Afternoon, " );
- else
- document.write( "<h2>Good Evening, " );
- }
- // determine whether or not there is a cookie
- if ( document.cookie )
- {
- // convert escape characters in the cookie string to their
- // english notation
- var myCookie = unescape( document.cookie );
- // split the cookie into tokens using = as delimiter
- var cookieTokens = myCookie.split( "=" );
- // set name to the part of the cookie that follows the = sign
- name = cookieTokens[ 1 ];
- }
- else
- {
- // if there was no cookie then ask the user to input a name
- name = window.prompt( "Please enter your name", "GalAnt" );
- // escape non-alphanumeric characters in the name string
- // and add name to the cookie
- document.cookie = "name=" + escape( name );
- }
- // write the greeting to the page
- document.writeln(
- name + ", welcome to JavaScript programming!</h2>" );
- // write the link for deleting the cookie to the page
- document.writeln( "<a href = \" JavaScript:wrongPerson() \" > " +
- "Click here if you are not " + name + "</a><br/>" );
- // write the random image to the page
- document.write ( "<img src = \"" +
- pictures[ Math.floor( Math.random() * 7 ) ] +
- ".gif\" width= \" 105 \" height= \" 100 \" /> <br/>" );
- // write the random quote to the page
- document.write ( quotes[ Math.floor( Math.random() * 3 ) ] );
- // create a window with all the quotes in it
- function allQuotes()
- {
- // create the child window for the quotes
- quoteWindow = window.open( "", "", "resizable=yes, toolbar" +
- "=no, menubar=no, status=no, location=no," +
- " scrollBars=yes" );
- quoteWindow.document.write( "<p>" )
- // loop through all quotes and write them in the new window
- for ( var i = 0; i < quotes.length; i++ )
- quoteWindow.document.write( ( i + 1 ) + ".) " +
- quotes[ i ] + "<br/><br/>");
- // write a close link to the new window
- quoteWindow.document.write( "</p><br/><a href = \" " +
- "JavaScript:window.close()\">" +
- " Close this window </a>" )
- }
- // reset the document's cookie if wrong person
- function wrongPerson()
- {
- // reset the cookie
- document.cookie= "name=null;" +
- " expires=Thu, 01-Jan-95 00:00:01 GMT";
- // after removing the cookie reload the page to get a new name
- location.reload();
- }
- // open a new window with the quiz2.html file in it
- function openQuiz()
- {
- window.open( "quiz2.html", "", "resizable = yes, "+
- "toolbar = no, menubar = no, status = no, " +
- "location = no, scrollBars = no");
- }
- // -->
- </script>
- </head>
- <body>
- <p><a href = "JavaScript:allQuotes()">View all quotes</a></p>
- <p id = "quizSpot">
- <a href = "JavaScript:openQuiz()">Please take our quiz</a></p>
- <script type = "text/javascript">
- // variable that gets the last midification date and time
- var modDate = new Date( document.lastModified );
- // write the last modified date and time to the page
- document.write ( "This page was last modified " +
- modDate.toLocaleString() );
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement