Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript, continued.

Similar presentations


Presentation on theme: "JavaScript, continued."— Presentation transcript:

1 JavaScript, continued

2 Testing Multiple Conditions

3 Operations on Booleans
AND OR Are all of them true? && Is it a big dog? (size==“big” && pet==“dog”) Number between 5 and 10 (num>=5 && num<=10) Are any of them true? || Is it either blue or black? (color==“blue” || color==“black”) Number less than 10 or greater than 20 (num<10 || num>20)

4 Is greater than or equal to
Operators Conditional Operator Meaning && and || or ! not Operator Meaning == Is equal to != Is not equal > Is greater than < Is less than >= Is greater than or equal to <= Is less than or equal to Logical

5 Last step of Thursday lab
Greeting to say one of the following: 8 pm-5 am Good Night (THIS MUST BE A SINGLE TEST) 5 am–noon Good Morning Noon-5 pm Good Afternoon 5 pm-8 pm Good Evening

6 onload

7 JavaScript needs to be “called”
Need an event to change things Mouse actions onclick onmouseover onmouseout Other events: when a new page is loaded onload

8 onload Using JavaScript to create content No user input! Comes up when page LOADS <body onload=“any JS statement”>

9 Print Msg onload Create a function Place it at the top of the page
No parameter Returns a string Place it at the top of the page

10 Saving information

11 Saving information Can I keep information between calls to a function?
Why would I want to do it? Possibilities Store and retrieve values from the HTML page Examine what is currently there: class, src Have a JavaScript variable OUTSIDE the function Known as a global variable

12 Saving a variable’s value
If the procedure sets the value, it gets the same value every time Instead, initialize it outside the function and change it in the function

13 Example: Building a Carousel of Pictures

14 Cycling through an array (1)
Keep track of the position If the procedure sets the value, it gets the same value every time Set an initial value outside the function and change it in the function

15 Add a carousel CSS and images on calendar

16 Cycling through an array (2)
Is there a way to cycle through an array? Check the current value and select next one based on it Need to look at the end of the string Need to use same length names stringname.slice(-length)

17 Strings (Only need if reading a file name)

18 What Can We Do With Strings?
Concatenation: builds them up Also want to break them up Referred to as “substrings” Lots of functions Referenced like Date objects stringname.function() Excellent summary

19 Addressing Parts of a String
Two concepts: position and length POSITION Like arrays, begins with position 0 First character is position 0 Can also use negative numbers! Means start from end of string, not beginning LENGTH To find the length of the string: stringname.length No parentheses! An attribute, like value, src, className when using getElement Substrings have lengths too

20 Some Useful Functions slice(startpos,untilpos) indexOf(string)
Position of the first found occurrence lastIndexOf(string) Position of the last found occurrence slice(startpos,untilpos) Substring from position 1 to position 2. can use negative number. substr(startpos,length) Substring from start position for number of chars substring(startpos,untilpos) Substring from position 1 to position 2


Download ppt "JavaScript, continued."

Similar presentations


Ads by Google