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.js
file, create astring
variable 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 atrue
orfalse
based on whether or not the the word “The” (or similar) matches the start of thestring
. - Using
String.endsWith()
, log whether or not thestring
is a question. - Using
String.includes()
, log atrue
orfalse
based on whether or not thestring
contains the word “the” (or similar). - Using
String.indexOf()
, log theindex
of 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 thestring
as 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