Bitpath

Lesson 1 · Unit 05

Strings

Cut, clean, search and rebuild text

13 exercisesabout 3 min

What you practise

  • Strings never change in place, split, join, trim, replace, includes, slice, padStart, upper and lower case

Try a question from this lesson

Pick one

The second line asks for an upper-case version of the name. What does the third line print?

JavaScript
let name = "ada";
name.toUpperCase();
console.log(name);

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Strings never change

A string has methods: functions you call with a dot, like push on an array.

There is one big difference. An array method like push changes the array. A string method never changes the string. It returns a new string, and you keep it by storing it.

Also new here: console.log takes several values, separated by commas, and prints them on one line with a space between.

JavaScript
let name = "ada";
name = name.toUpperCase(); // keep it
const low = "Hi".toLowerCase();

console.log(name);      // ADA
console.log(name, low); // ADA hi

Concept

split and join

split turns one string into an array of pieces. You say where to cut.

join is the way back: it glues the items of an array into one string. You say what goes between them.

Split, change the pieces, join: a great deal of text work is those three steps.

JavaScript
const words = "to be or not".split(" ");
console.log(words.length); // 4
const glued = words.join("-");
console.log(glued);        // to-be-or-not

const letters = "abc".split("");
console.log(letters.length); // 3

10 more exercises in the app

  • 3× type the answer
  • 2× multiple choice
  • 2× fill the blanks
  • 1× true or false
  • 1× match the pairs
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy