1 / 28

CSC 112 Intro to Computer Programming in JavaScript Spring 2005

CSC 112 Intro to Computer Programming in JavaScript Spring 2005. Internet and WWW. Internet and WWW are not the same – Internet includes email and other things Internet is the computers and the means by which they physically connect to each other.

jaxon
Télécharger la présentation

CSC 112 Intro to Computer Programming in JavaScript Spring 2005

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. CSC 112 Intro to ComputerProgramming in JavaScript Spring 2005

  2. Internet and WWW • Internet and WWW are not the same – Internet includes email and other things • Internet is the computers and the means by which they physically connect to each other. • World Wide Web is the logical means of accessing the files on these computers, primarily as web pages.

  3. Using the World Wide Web • Browsers Netscape Navigator Internet Explorer • Plug-ins Java Macromedia Flash Acrobat Reader … • Search Engines Yahoo and many others

  4. Internet Protocols • TCP/IP – Transmission Control Protocol / Internet Protocol • FTP – File Transfer Protocol • http – Hypertext Transfer Protocol • telnet – for remote login to other computers, with local computer as dumb terminal

  5. IP Addresses • Example – 123.45.67.89 • For specific computers on the Internet • Information is passed between them in packets • A named address (next slide) is converted to an IP address by a Domain Name Server (DNS)

  6. Named AddressesURL’s – Uniform Resource Locators http://www.music.sony.com/Music/index.html http is the protocol com is the domain – others are edu, org, gov, … www. music.sony.com is the server computer Music is the folder on the server computer index.html is the file in the Music folder

  7. Hypertext Markup Language • Describes with tags how web page should be formatted for display by browser • Container tags, thus <BODY> and </BODY> • Non container tags, thus <BR> or <HR> • Tags must be properly nested

  8. Basic Skeleton of an HTML Page <HTML> <HEAD> <TITLE> … </TITLE> </HEAD> <BODY> … </BODY> </HTML>

  9. For an unordered list <UL> <LI> <LI> … </UL> For an ordered list <OL> <LI> <LI> … </OL> Tags for Lists

  10. Attributes of HTML Tags • Describe how to accomplish a result • Attributes may or may not have values, as in <P ALIGN=left> …. </P> • BODY attributes include colors for links and for background • FONT attributes include color and size

  11. Hypertext Links • <A HREF=“some URL“> anchor text </A> (Absolute or relative URL’s) • <A HREF=“#fragment identifier”> anchor text </A> • <A NAME=“a named anchor”> </A>

  12. Images in Web Pages • Images appear when page is loaded, with <IMG SRC=“URL for image file”> • Image files for web pages are of type GIF or JPG • Image files are loaded via links, with <A HREF=“URL for image file”> some text </A>

  13. Programming • The Client-Server Model • Compiling versus Interpreting • Embedding JavaScript code in a web page • The Syntax or grammar of a P.L. (programming language) • Variables – numbers and strings and booleans • Operators – arithmetic and comparison • Concatenating strings with the overloaded + operator • Expressions – modifying precedence with parentheses • Statements – the assignment operator, the terminal semicolon

  14. Translating a Program to ML • Assembler Language (AL) • High Level Languages (HLL’s) Interpreting – Translate and execute on the fly Compiling – Translate source program to object program, then execute it, retaining translation for subsequent execution

  15. JavaScript Objects Thus, var foo = new Object() Objects may contain primitives of type number, string, or boolean other objects ! methods, or functions Thus, function foobar (){ statement; statement; … }

  16. Creating Forms with HTML <FORM … > <INPUT TYPE=text …> <INPUT TYPE=button …> <INPUT TYPE=reset …> <INPUT TYPE=checkbox …> <INPUT TYPE=radio …> <SELECT …> <OPTION …> <OPTION …> … </SELECT> <TEXTAREA …> </TEXTAREA> </FORM>

  17. Processing Forms with JavaScript Events, such as onclick and onchange Functions as event handlers Local variables in functions Converting strings to numbers with parseFloat() Arrays, as with var numbers = new Array() The elements array, automatically, for all of the items in the form selectedIndex for pull-down menus

  18. Arrays • The array is a special kind of object var foo = new Array ( ); where the items in foo are indexed by integer values, thus foo[1], foo[j], foo[2*k+3]… • If the first index value is 0, it is a standard array, as with elements[ ] and options[ ] • A property of an array is its size, as with foo.length

  19. Basic Tags for Tables <TABLE> <TR> <TD> <TD> … <TR> <TD> <TD> … </TABLE>

  20. Attributes of TableTags • <TABLE> … </TABLE> ALIGN, BGCOLOR, BORDER, CELLPADDING, CELLSPACING, HEIGHT, WIDTH • <TR> … </TR> ALIGN, VALIGN, BGCOLOR • <TD> … </TD> ALIGN, VALIGN, BGCOLOR, COLSPAN, ROWSPAN

  21. Control Structures • Sequential Processing do A, then B, then C, … • Conditional Processing (branching or selection) if A is true, then do B, else do C • Iterative Processing (looping or repetition) while A is true, do B {and test A again}

  22. Conditional Processing Comparison operators Boolean variables Logical operators for and, or, not if (boolean condition) { statement; statement; … } else { statement; statement; … }

  23. Iterative Processing • Must have three components - Initialize the loop control variable (lcv) • Test the lcv for termination • Update the lcv to next value • Thus, we have the for statement for (j = 0 ; j < 10 ; j += 1) { statement; statement; } • We also have the while statement j = 0; while (j < 10) { statement; j += 1; }

  24. Understanding Iteration • Word Problems To compute the number of days in the years 1950-2000 days = 0; for (years = 1950 ; years <= 2000 ; years++) if (years % 4 == 0) days += 366; else days += 365; • Tracing Iteration for (j = 1 ; j <= 3 ; j++) for (k = 0 ; k < j ; k++) document.write (j + “ ” + k + “<BR>”);

  25. Functions • Function definition (in the HTML head), thus function foobar (a, b, c) { statement; statement; } where a,b,c are formal parameters. • Function invocation or function call, thus foobar(5, j, “Hello”); where the values in parentheses are actual parameters; when foobar is called, a=5, b=j, and c=“Hello”

  26. Cookies • Name - Value pairs are just text strings! • When server responds to client request, it sends cookie to be stored on client. • When browser sends request to server, it retrieves cookie (if present) for server. • The GOOD for customizing user interface to server for implementing shopping carts • The BAD without user knowledge or consent contribute to junk mail and spamming • JS code to SetCookie(), GetCookie(), getCookieVal(), DeleteCookie()

  27. Sources of Errors • Typing errors • Syntax errors – incorrect grammar syntax is how a message is given • Logical errors – incorrect semantics semantics is the meaning • Poor algorithms • Bad input values – GIGO • Incorrect specification of the problem

  28. Computer Ethical Issues • Privacy versus security • Spamming • Email usage • Hacking • Ownership and piracy …

More Related