1 / 9

COMM 1213 H1 COMP 4923 X1

COMM 1213 H1 COMP 4923 X1. JavaScript 3 (Readings: Ch. 15 Knuckles). Outline. FOR Loop WHILE Loop Verifying Input using a Loop Sodexo Survey revisited. Repetition via Loops (Ch.15). Sets initial loop index value. The FOR Loop <HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript><!--

hea
Télécharger la présentation

COMM 1213 H1 COMP 4923 X1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMM 1213 H1COMP 4923 X1 JavaScript 3 (Readings: Ch. 15 Knuckles)

  2. Outline • FOR Loop • WHILE Loop • Verifying Input using a Loop • Sodexo Survey revisited

  3. Repetition via Loops (Ch.15) Sets initial loop index value • The FOR Loop <HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript><!-- for (i=1; i<=1000 ; i=i+1) { document.write(i+"<BR>"); } //--></SCRIPT> </HEAD> <BODY> <P> </BODY> </HTML> Sets Boolean condition on which to stop Sets amount to change index on each pass of loop What would happen if the condition i<=1000 was changed to i<=10000000 ?

  4. Using For Loops • Processing the Pizza Toppings Form • Figure 15.4 • Generating random lottery numbers • Figure 15.6

  5. The WHILE Loop • Used when the number of times to loop is not known at the time of writing the code. • Consider the question: Starting from 1, how many numbers must be added until the total exceeds 25,000. • Algorithm: sum = 0 i=1 while sum <= 25000 sum = sum + i i= i+1 • Program – Figure 15.8

  6. Verifying Input <HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript><!-- var pass; pass=prompt("Enter Your Password.",""); correct=false; while(!correct){ if((pass!="buddy")&&(pass!="pal")){ alert("You have entered an incorrect password."); pass=prompt("Enter Your Password. Get it right this time.",""); } else{ correct=true; } } //--></SCRIPT> </HEAD> <BODY BGCOLOR="#FFFFCC"> <P><FONT SIZE="+3"><B>This page contains the darkest secrets of the universe.</B></FONT> </BODY> </HTML> Figure 15.10

  7. Other Fun with LOOPs • Nested Loops and Tables Figure 15.12 • The Sodexo Food survey revisisted • The Sodexo Food survey with a Loop • Uses an array to hold the Food types • The Sodexo Food survey with HTML output

  8. Resources • http://www.w3schools.com/js/js_examples.asp • http://www.tizag.com/javascriptT/index.php • http://www.js-examples.com/page/javascripts.html • http://javascript.internet.com/

  9. THE ENDdanny.silver@acadiau.ca

More Related