1 / 30

Wednesday

Wednesday. Homework 1 = due by email by 4pm Submit to gillw3@rpi.edu (zip your files). Apps v. web apps. Discuss…. JS. Javascript. Javascript. Client Side Scripting Language Object Oriented Event Driven. Places JS Lives. An External File <head> of an HTML file

eryk
Download Presentation

Wednesday

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. Wednesday • Homework 1 = due by email by 4pm • Submit to gillw3@rpi.edu (zip your files)

  2. Apps v. web apps • Discuss….

  3. JS Javascript

  4. Javascript • Client Side Scripting Language • Object Oriented • Event Driven

  5. Places JS Lives • An External File • <head> of an HTML file • In the <body> of an HTML page • (after all the elements it may reference) • JS can be used in multiple locations in the same HTML document

  6. A link to an external javascript document A JS Script coded in the <head> of an HTML document

  7. External JS Files Don’t put another set of <script> tags inside your external JS docs

  8. JS Inside HTML

  9. Variables • All are untyped • Local Variables • Accessible only inside the current function • Global by assignment

  10. Literals

  11. Operators

  12. Control Structure • If • If / else • Switch • For • While • For (object)

  13. IF • If • If / Else

  14. Switch

  15. Loops • For • While

  16. Looping over an Object

  17. Functions • Declaring a Function • Calling a Function

  18. Events http://www.w3schools.com/jsref/jsref_events.asp

  19. Timer Events • Run JS in the future • setTimeout(“js code”, milliseconds); • Code must be in quotes!!!!!!!!! • setTimeout(“print_time()”,1000);

  20. Timer Events • Do every N seconds: Function do(){ ….. Code; setTimeout(“do()”,1000); }

  21. Events

  22. JS Objects • Properties • A value held by an object • Methods • Act upon an object A string property A string method

  23. String Methods • str.substr(start, length) • Returns a sub string • str.indexOf(seach) • Returns position of the first instance of search • str.replace(bad, good) • Replaces bad text with good text • str.split(delimiter) • Breaks string into an array at every instance of delimiter

  24. String Properties • str.len • Returns length of a string

  25. Math Methods • Math.ceil(x) • Rounds up to the next integer value • Max(x,y) • Picks the larger of the two arguments • Math.random() • Returns a random number between 0.0 and 1.0

  26. Document Object • Properties • Document.URL • Returns current url and query string • Methods • document.writeln() • Prints a line in the current document • Document.getElementById(id) • returns an HTML element with the ID you provide

  27. Debugging • Web dev tool bar: • Click the red exclamation marks to see errors • alert(somevar); • alert(‘working at line 36’);

  28. In Class • Write a ‘hello world’ script put it inside the body of an HTML document • View the generated html … what’s happened here? • Write a ‘hello world’ function – call it on body onload • View the generated html … what’s happened here?

  29. In Class • Write a script that generates the following text: 1+1, 1+2, …., 1+10 • If the user clicks on one of these items, produce an alert box with 1+1 = 2 (for example)

More Related