Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript Functions. CSS Inheritance Which formatting applies? x y z input { display: block; } input.pref { background:red; } If you have a selector.

Similar presentations


Presentation on theme: "JavaScript Functions. CSS Inheritance Which formatting applies? x y z input { display: block; } input.pref { background:red; } If you have a selector."— Presentation transcript:

1 JavaScript Functions

2 CSS Inheritance

3 Which formatting applies? x y z input { display: block; } input.pref { background:red; } If you have a selector with no class, it applies to all of those elements REGARDLESS of class

4 Assignment Statements

5 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

6 example A = B + C; Cubby Hole 2: add this value Cubby Hole 1: take this value Cubby Hole 3: place it here

7 CUBBY HOLES  3 types of cubby holes  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

8 Using Functions

9 What is a function?  Collection of statements that can be invoked as a unit  Can take parameters  Can return values  Can be used multiple times  Can call without knowing how they work

10 Parameters  Call a function with a different value every time  MUST give it everything that it expects  Some functions don’t require parameters  For alert  One parameter, the string to print

11 Inputs Output Black Box

12 Parameters Return Function Cubby holes I can just read Cubby hole I can just write

13 Format of a Function  Function_name(parm,parm);  Always needs () even if no parameter  Function_name();

14 The rules  The order of the parameters matter  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

15 Invoking a Function  Can be a statement by itself  alert(‘print’);  Or it can return a value and be part of an expression  sample.here.value=Date();  (more about Date later)

16 Forms and Functions

17 Form fields are cubby holes  Two cubby holes that we have learned about:  value: something that can be changed  src: the picture file

18 More about Date()  Returns an “object”  Collection of information  Year, month, day, house, minutes, seconds, milliseconds  Will cover way to get the pieces next week

19 Another useful function  Math.random()  Returns a value between 0 and 1  One of a series of mathematical functions  members of a collection called Math  each are prefixed by “Math.”

20 Using Functions  As a parameter  alert(Date());  As part of an expression  10*Math.random();


Download ppt "JavaScript Functions. CSS Inheritance Which formatting applies? x y z input { display: block; } input.pref { background:red; } If you have a selector."

Similar presentations


Ads by Google