Download presentation
Presentation is loading. Please wait.
Published byReynold Richardson Modified over 8 years ago
1
JavaScript Loops
2
Looping Want to be able to do things more than once Basic: for (var i=initial; while-clause; increment) { statement; }
3
Looping through an array Attribute of an array: length Because first entry is 0, loop while < length
4
Nesting Loops When you need to work with two or more numbers Examples Creating a table Computing area of a range of rectangles …
5
While Want to end the loop based on some condition Need to be changing something to cause it to end Test first: while (condition) { statements; } Test last: do { statements; } while (condition);
6
onload
7
Using JavaScript to create content No user input Comes up when page LOADS
8
JavaScript Strings
9
JavaScripts Strings Easier Length: stringname.length Functions: stringname.function() Concatenation: + or stringname.concat() Lots more functions Use of negative index to come from end Built-in regular expressions Excellent summary
10
Useful Functions charAt()Character at the position indexOf()Position of the first found occurrence lastIndexOf()Position of the last found occurrence replace()Replaces the matched substring with a new substring search()Position of the match split()Splits a string into an array of substrings substr()Substring from start position for number of chars substring()Substring from position 1 to position 2 toLowerCase()Converts a string to lowercase letters toUpperCase()Converts a string to uppercase letters trim()Removes whitespace from both ends of a string
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.