Download presentation
Presentation is loading. Please wait.
1
Exam Prep
2
Exams: Two Exams I just need to know how many seats Google form
12 (section 002 – 11 am) 8 (section 001 – 9:30 am) I just need to know how many seats Google form
3
Check pdf processing Download the test pdf
Fill in your name and save it Close the pdf Reopen and check that it changed
4
JavaScript Strings
5
What We Want To Do User enters: Mary Smith
We want to respond: Hi Mary! We know how to concatenate. How do we take part of a string?
6
Think of Scrabble tiles Each tile is a
Strings Think of Scrabble tiles Each tile is a Letter Number Punctuation mark Space (blank)
7
A literal string must be inside double quotes or single quotes
What is a String? A literal string must be inside double quotes or single quotes “this is a string” and this is not a string. Remember not to cut and paste
8
Concatenating (formally)
It means combining two or more things into one thing + Anything can be concatenated “awe” + “some” = “awesome” Whitespace only matters inside quotes “a”+“b” same as “a” = “b” “a ” + “b” NOT the same as “a” + “b”
9
Substring A substring is also a String
A substring is a part of another string “cake” is a substring of “birthday cake” so are “day”, “thd”, and “y cake” “they” is not, neither is “hello” or “dude” Will come back to how to extract substrings
10
Referencing characters
Each character has a position Note that it starts at 0, not 1 H I M O 1 2 3 4 5
11
JavaScripts Strings 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
12
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 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
13
Lab Create a form that takes a full name and a birth year
Pass both as parameters Procedure needs to Extract first name Compute age Print a message Happy nn Birthday, FirstName
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.