Reviewing key concepts JavaScript Reviewing key concepts
3 BIG IDEAS Assignment Statements Functions Forms
Idea 1: assignment statements
Holding information A computer doesn’t understand values It takes locations and does what you tell it It knows about “cubby holes” A JavaScript Statement Takes information from a cubby hole Does what you say And then puts it where you say Holding information
A = B + C; Cubby Hole 2: add this value Cubby Hole 3: place it here Cubby Hole 1: take this value example
CUBBY HOLES 3 types of cubby holes Differences Fields in a form Function input and output Specially defined ones Differences Some you can only read Some you can only write Some you can do both CUBBY HOLES
using Functions
Output Black Box Inputs
Return Parameters Function Cubby hole I can just write Cubby holes I can just read
Isolation A function can be called from ANYWHERE It knows nothing about the outside world You need to tell it EVERYTHING it needs Isolation
The rules The order of the parameters matter Only a single output 5 - 3 different than 3 -5 Any number of parameters can be defined Fixed for any specific function Only a single output Optional in general Same for any specific function The rules
Returning a value Use the function as a value Contrast with form.field.value = function(parm1, parm2); difference = subtract(minuhend,subtrahend); Contrast with alert(string); append(form.field.value,’end’); Returning a value
creating Functions
Writing: alert, log Conversions: strings and numbers Many more: google them Existing functions
Need to define Inputs Outputs What to do Building our own
Inputs: read only These are the parameters Order matters Need a way to reference them Position 1, position 2, … Cubby holes Better to use meaningful names Each name is just a pointer to the cubby hole Inputs: read only
output: write once Use a RETURN statement A write-once cubby hole Only way to access is the RETURN statement Once you set it, the function is ended Can have a simple value or more (e.g., concatenating strings) output: write once
WHAT TO DO Series of statements: the recipe Can use Assignment statements Function calls Can use Literals (5, “ “) parameters Specially defined locations (variables) WHAT TO DO
Idea 3: Forms
Form fields are cubby holes Two cubby holes that we have learned about: value: something that can be changed src: the picture file Form fields are cubby holes