Design - Specfication

Document Sample
Design - Specfication Powered By Docstoc
					           DePaul University
               SNL 262
       Advanced Web Page Design

  Supplemental - 3 Additional Examples

              Instructor: David A. Lash


AdvWeb-1/11
                       parseInt()

   parseInt() - Converts a string to a number
      –   stringvar = “12”;
      –   numvar = parseInt(stringvar);

      –   After this numvar is the number 12;

      –   stringvar = “1515 East Wilson”
      –   numvar = parseInt(stringvar);

      –   After this numvar = number 1515 the non
          numerical portion of the string is ignored.




AdvWeb-2/11
           A Big parseInt Example

   Write a program that
      –   prompts a user for a number from 1-12
      –   If a valid number is input, then it prints out the
          corresponding month and the number of days in
          that month.
      –   If an invalid number is input, ask the user to input
          the number again. (Continue to do this until a vald
          number is input).




AdvWeb-3/11
            A Big parseInt Example
 <HTML>
 <HEAD><TITLE>User Response Example</TITLE></HEAD>
 <BODY>
 <SCRIPT LANGUAGE="JavaScript1.3">
    months= new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
    "Aug", "Sep", "Oct", "Nov", "Dec" );
    days = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
    flag="TRUE";
    while ( flag == "TRUE" ) {
         userinput = window.prompt("Enter Mon Numb (between 1-12)");
         numinput = parseInt( userinput );
         if ( userinput > 0 && userinput < 13 ) {
                   document.write("Month is=" + months[numinput-1] );
                   document.write(" Numb of days=" + days[numinput-1]);
                   flag="FALSE";
         }
         else {
                   window.alert("Sorry please a number between 1-12");
         }
      }
 </SCRIPT></BODY></HTML>.
  AdvWeb-4/11
ttp://www.depaul.edu/~dlash/extra/Advwebpage/examples/Suppl_MonthLookup.
                 Another Example

   Write a program that
      –   prompts the user for numbers an unlimited
          amount of time. Continues until the character
          “STOP” is entered.
      –   If an invalid number is input, a alert is sent to the
          user, that input ignored and the user is asked to
          re-enter the number.
      –   Once a set of valid numbers are entered, the
          average of the numbers is printed out.




AdvWeb-5/11
                  Another Example
<HTML><HEAD><TITLE>User Response Example</TITLE></HEAD>
<BODY><SCRIPT LANGUAGE="JavaScript1.3">
   ctr=0; total=0;
   flag="TRUE"; aver=0;
   numb = new Array();
   while ( flag == "TRUE" ) {
        userinput = window.prompt("Enter A Numb (Enter STOP when
   Done)");
        if ( userinput == "STOP" ) flag="FALSE";
        else {
            numinput = parseInt( userinput );
            if ( userinput == "NaN" ) {
                    document.write("Input not a valid number=" +userinput
   );
             }
           else {
              numb[ctr] = numinput;
              total=total+numinput;
              ctr = ctr + 1;
            }
        }
      }
 AdvWeb-6/11
   A Big parseInt Example -- Part II
   if ( ctr > 0 ) aver = total/ctr;
   document.write("Average=" + aver );
   document.write(" Total=" + total );
   document.write(" ctr=" + ctr );
</SCRIPT></BODY></HTML>




http://www.depaul.edu/~dlash/extra/Advwebpage/examples/Suppl_BigAver.htm




AdvWeb-7/11
        Another Example - Part I

<HTML><HEAD><TITLE>User Response Example</TITLE><SCRIPT>
function writeit ( n ) {
      for (i=0; i<5; i++ ) {
        document.write( " i=" + i + " numb=" + n[i] );
      }
      document.write("<BR>");
   }
</SCRIPT></HEAD>




AdvWeb-8/11
         Another Example - Part II

  <BODY> <SCRIPT LANGUAGE="JavaScript1.3">
     ctr=0; total=0;
     flag="TRUE"; aver=0;
     numb = new Array( 2, 4, 6, 8, 10 );
     document.write("Original Array " + "<BR>" );
     writeit( numb );
     temp=numb[0];
     numb[0] = numb[1];
     numb[1] = temp;
     document.write("Switch Array " + "<BR>" );
     writeit( numb );
     x=2;
     numb[x+2] = 151;
     document.write("Last One " + "<BR>" );
     writeit( numb );
  </SCRIPT></BODY></HTML>

http://www.depaul.edu/~dlash/extra/Advwebpage/examples/Suppl_Switch.htm
AdvWeb-9/11

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:7/1/2013
language:English
pages:9