String Methods, online
Six activities your students do on their own devices. See who's finished, and their scores.
String Methods in one minute
What students need to know
toLowerCase() returns a new string with all lowercase letters. trim() cleans up whitespace at the start and end of a string.
toUpperCase() converts every letter to uppercase in a new string. JavaScript uses camelCase, so it must be toUpperCase.
Mistakes students make
- 'trim' must be lowercase - a capital T causes an error.
- Method names are camelCase - it should be toUpperCase, not touppercase.
- Missing parentheses - toUpperCase() needs to be called.
- Missing parentheses - trim() needs to be called.
What students will learn in this module
Every question in Module 30
Quick questions
- Does toUpperCase() return a new string in all caps?AYesBNo
- Does toLowerCase() change the original string?ANoBYes
- Does trim() remove whitespace from the start and end?AYesBNo
- Is 'touppercase' with no capitals valid JavaScript syntax?AYesBNo
- Do these string methods need parentheses to be called?ANoBYes
Key terms
Students type the meaning of:
toUpperCase()
Match the pairs
name.toUpperCase()Match it to what it doesname.trim()Match it to what it doesConverts every letter of a string to lowercaseMatch it to what it doesRemoves leading and trailing whitespace from a stringMatch it to what it doestext.touppercase()Match it to what it doestext.Trim()Match it to what it doesFill in the blanks
console.log(name.___________());
Hint: Type the method that converts a string to all uppercase.
console.log(name.___________());
Hint: Type the method that converts a string to all lowercase.
console.log(name.____());
Hint: Type the method that removes whitespace from both ends.
let upper = word.___________();
Hint: Type the method that converts a string to all uppercase.
let trimmed = input.____();
Hint: Type the method that removes whitespace from both ends.
Spot the error
Question 1
Alet a = " hi ";Bconsole.log(a.Trim());Cconsole.log(a);
Question 2
Alet b = "Hi";Bconsole.log(b.touppercase());Cconsole.log(b);
Question 3
Alet f = "Hi";Bconsole.log(f);Cconsole.log(f.toUpperCase);
Question 4
Aconsole.log(g.trim);Blet g = " hi ";Cconsole.log(g);
Question 5
Alet h = "Hi";Bconsole.log(h.toUpperCase());Cconsole.log(h);Dconsole.log(h.touppercase());
