String Crafter — JavaScript

Work with strings: 12 levels of slice, split, replace, regex match and template literals. A JavaScript string manipulation game for mastering text.

What you learn in this game

.toUpperCase() returns a new string with all the letters changed to capital. The original string doesn't change.

.trim() removes the whitespace at the start and end of a string. Spaces in the middle stay. Methods can be chained.

.includes(searchString) returns true if the string contains searchString, false if not. It's case-sensitive.

.startsWith(prefix) returns true if the string starts with prefix. .endsWith(suffix) checks the suffix.

.slice(start, end) takes a part of the string. start is the starting position (from 0), end is the ending position (not included).

.indexOf(searchString) returns the first position where searchString is found (from 0). It returns -1 if not found.

What the levels ask

  1. Change the text to all uppercase.
  2. Change the text to all lowercase.
  3. Remove the excess spaces at the start and end of the text, then change it to uppercase.
  4. Check whether the text contains the word "batik" (case-insensitive). Change it to lowercase first, then check.
  5. Check whether the postal code starts with "60" (the Surabaya area).
  6. Take the first 5 characters of the string, then convert them to uppercase.
  7. Find the position of the word "dunia" in the text. Convert to lowercase first so the search is case-insensitive.
  8. Replace the word "lama" with "baru" in the text.
  9. Change the separator from a space to a hyphen "-". Split by space, then join with "-".
  10. Reverse the order of the words in the sentence. Split, reverse the array, then join it back.
  11. Turn the title into a URL slug: all lowercase and spaces replaced with "-".
  12. Make a hashtag: remove the spaces at the start/end, all lowercase, replace spaces with an underscore, then take the first 15 characters.