Excuse my mess of notes, I might have even typed some of this wrong. Just typing as fast as I can as she moves quickly. Today’s class will go over some JavaScript. Next week we’ll look at PHP. See new syllabus online. Will be quizzed. JavaScript isn’t Java. JavaScript has 2 versions, but we’ll be talking about client-side JavaScript, which means processing is done by the browser, not the server.
JavaScript can put dynamic text into an HTML page, react to events (button click, rollover, etc.), change the content of an HTML element, validate form data (but don’t count on it as the only validation), detect visitor’s browsers, get date/times, get localization, create cookies, etc.
- Use semi-colons at the end of statements for clarity.
- JS is case-sensitive; pay attn to case and spellings, or it can trip you up. var does not equal Var. Var wil not work like var.
- Variables have to be alpha-numeric or have an underscore.
- JS ignores white-space, like HTML.
- Single quotes vs. double quotes: you can use either, just be consistent.
- Naming functions/variables: you can have your own pattern in naming conventions; just be consistent.
- Variable names can’t begin with a number, but can be in the middle or end. Underscores are okay.
The DOM (document object model) can be manipulated with JavaScript.
A javascript statement is a command for the browser; tells the browser what to do. Statement block: the brackets and all in between {}
Variable — contemporary container to store a value. Local (inside a function) and global (at the top of the page). Global: var_x=4, then var_x=2 : 2 would override 4. Local: function cat() { var_x = 4 } only the cat function can use 4. Nothing else. It’s can help to put all the global variables at the top (organization tip). You can even just declare it, and not have to define a value for it. JS reads code from top to bottom, so order stuff in order of how it should be run. If x=2, and then further down x=4, whatever comes after that will read x as 4. Can’t change that unless you write a new function.
Operators: Something to affect the variable, whether you’re assigning it, adding to it, subtracting from it, etc. The (=) [assigning] in var_x=1 is the operator. A (+) [add, can also subtract, multiply, divide], (==) [is equal to], (===) [is equal to, and is an integer]. Structure works the same in PHP.
If/else statements and comparing things. If something happens, then do something else. The “Hi” popup will only happen if x does in fact equal 1. Else if: or if this happens, do this… If x equals 2, do this. Else: otherwise, do this…. If x does not equal 1 or 2, it does this.
(We’re opening up Dreamweaver, and giving it a try…
Formatting: it could go all on one line or indented; personal preference.
A String is text (paragraph, whatever). In quotations. Anything. document.write(“<h1>Hello</h1>”); NaN means “not a number. You can also round, max, and ciel (finding the top range of numbers) with Math: Math.round, Math.ciel, Math.average, etc.
POP QUIZ TIME!
Comments can be single-line (//) or multi-line (/* */). It’s nice to have JS begin with Author name, version, last updated, etc. Instantiating for loops.
Assignment for next week is to decide what your final project (web application) will be, and do a site map (flow diagram) for that project. At least 2 levels deep. Need at least 12 steps (tasks) (not to do one task, but various tasks; signing in, creating an account, etc.. A product catalog of some sort and login for the project is required. With a description of what your project is and what you expect users to do. (Show what happens if a path is successful (logging in) or if it fails (error page), etc. and all the pages planned for the web application).
Also, do assigned reading.
Unrelated Note:
If you haven’t already, please change your RSS subscriptions to my new feed URL: http://feeds.feedburner.com/SushiRobots. Thanks!