Day 4 - Strings and the DOM
Housekeeping
- CPNT 262 Assignment 1 announced
- More Achievements for Round 1 announced after lunch
- CPNT 260 Final Project marks released
1. Strings and string methods
Activity: String method practice
In pairs, practice using string methods:
- Go to wikipedia and choose a sentence or phrase that interests you (or doesn’t);
- In a new
client.jsfile, create astringvariable containing your selected phrase; - Try using the following string methods on your phrase:
- Using
String.length, log the sentence “This phrase has [Number] characters”, replacing[Nunber]with the actual number of characters in thestring. - Using
String.startsWith(), log atrueorfalsebased on whether or not the the word “The” (or similar) matches the start of thestring. - Using
String.endsWith(), log whether or not thestringis a question. - Using
String.includes(), log atrueorfalsebased on whether or not thestringcontains the word “the” (or similar). - Using
String.indexOf(), log theindexof the first matching word (i.e. “the”) found in thestring. - Add the
<textarea>counter back into the starter form. - Using
String.split(), log each character in thestringas an array.
- Using
2. The Document Object Model
Activity: DOM practice
In pairs:
- Using
document.querySelector()andElement.innerHTML, try printing the console logs you created in the previous activity to a<p>element on an HTML page; - Using
prompt()print dynamic content to an HTML page using user input.
Lab Time
- Complete this morning’s activities (or work on the below achievements for marks instead);
- CPNT 262:
- DSGN 270 Assignment 4

