Exam Prep
Exams: Two Exams I just need to know how many seats Google form Mon @ 12 (section 002 – 11 am) Fri @ 8 (section 001 – 9:30 am) I just need to know how many seats Google form
Check pdf processing Download the test pdf Fill in your name and save it Close the pdf Reopen and check that it changed
JavaScript Strings
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?
Think of Scrabble tiles Each tile is a Strings Think of Scrabble tiles Each tile is a Letter Number Punctuation mark Space (blank)
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
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”
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
Referencing characters Each character has a position Note that it starts at 0, not 1 H I M O 1 2 3 4 5
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
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
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