Presentation is loading. Please wait.

Presentation is loading. Please wait.

AdvWeb-1/11 DePaul University SNL 262 Advanced Web Page Design Supplemental - 3 Additional Examples Instructor: David A. Lash.

Similar presentations


Presentation on theme: "AdvWeb-1/11 DePaul University SNL 262 Advanced Web Page Design Supplemental - 3 Additional Examples Instructor: David A. Lash."— Presentation transcript:

1 AdvWeb-1/11 DePaul University SNL 262 Advanced Web Page Design Supplemental - 3 Additional Examples Instructor: David A. Lash

2 AdvWeb-2/11 parseInt() u 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.

3 AdvWeb-3/11 A Big parseInt Example u 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).

4 AdvWeb-4/11 A Big parseInt Example User Response Example 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"); }. http://www.depaul.edu/~dlash/extra/Advwebpage/examples/Suppl_MonthLookup.html l

5 AdvWeb-5/11 Another Example u 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.

6 AdvWeb-6/11 Another Example User Response Example 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; }

7 AdvWeb-7/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 ); http://www.depaul.edu/~dlash/extra/Advwebpage/examples/Suppl_BigAver.html l

8 AdvWeb-8/11 Another Example - Part I User Response Example function writeit ( n ) { for (i=0; i<5; i++ ) { document.write( " i=" + i + " numb=" + n[i] ); } document.write(" "); }

9 AdvWeb-9/11 Another Example - Part II ctr=0; total=0; flag="TRUE"; aver=0; numb = new Array( 2, 4, 6, 8, 10 ); document.write("Original Array " + " " ); writeit( numb ); temp=numb[0]; numb[0] = numb[1]; numb[1] = temp; document.write("Switch Array " + " " ); writeit( numb ); x=2; numb[x+2] = 151; document.write("Last One " + " " ); writeit( numb ); http://www.depaul.edu/~dlash/extra/Advwebpage/examples/Suppl_Switch.html l


Download ppt "AdvWeb-1/11 DePaul University SNL 262 Advanced Web Page Design Supplemental - 3 Additional Examples Instructor: David A. Lash."

Similar presentations


Ads by Google