×

javascript · level 1 · unit 3 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Strings come with tricks built in.

A is a trick a value knows how to do. Write the box name, a dot, then the method name and brackets. pet.toUpperCase() shouts in capitals and pet.toLowerCase() whispers in small letters.

.trim() cuts spaces off both ends, handy when someone types an extra space. .replace("B", "W") swaps the first B it finds for a W. Each method hands back a new string.

A is a fact a value knows about itself, so it needs no brackets. pet.length counts every letter, space and symbol in the string.

let pet = "Biscuit";
console.log(pet.toUpperCase());
console.log(pet.toLowerCase());
console.log(pet.replace("B", "W"));
console.log(pet.length);

You can line tricks up, so pet.trim().toUpperCase() trims first, then shouts.