1 / 9

The Web Wizard’s Guide To JavaScript

The Web Wizard’s Guide To JavaScript. Chapter 2 Enhancing Web Pages with JavaScript. Chapter Objectives. To understand the role of sequence in programming To learn how to use loops To learn how to use conditional branching To learn how to place JavaScript code into your HTML documents

yosefu
Télécharger la présentation

The Web Wizard’s Guide To JavaScript

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. The Web Wizard’s Guide To JavaScript Chapter 2 Enhancing Web Pages with JavaScript

  2. Chapter Objectives • To understand the role of sequence in programming • To learn how to use loops • To learn how to use conditional branching • To learn how to place JavaScript code into your HTML documents • To learn how to create external libraries of code you use often • To learn how to use a Web page that creates other Web pages • To understand how to create a Web page to test your code

  3. Sequence • Doing Things in a Given Order • Browsers execute statements in the order they are received. • Statements are placed in the HEAD within the <script></script> tag.

  4. Loops • Doing things repeatedly • The for loop • Initial expression • Test condition • Update expression

  5. Conditional Branching • Code that makes decisions • The if-else structure • Test a condition • One set of statements if condition is true • Another set of statements if condition is false • Take care to not confuse assignment (=) with equality (==)

  6. Where to Placing Scripts • Scripts can go in the HEAD or the BODY • Event handlers in BODY send values to functions in HEAD

  7. Code Libraries • Reuse your favorite scripts • Store code libraries in plain text files • Use the .js extension for code libraries • Reference your source libraries using the script tag. • <script type="text/javascript" language="javascript" src="mylibrary.js">

  8. A Page to Make HTML Code • Place the buildPage() function in mylibrary.js • The pagecontent variable stores code for an html page • The contents of pagecontent are placed in an on-screen text field.

  9. A Page to Test Code • Visitors type code into a text field • The eval() function executes the code

More Related