Skip to main content

JavaScript String Immutability — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript String Immutability lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Keep the result

    easy10 min

    Assign the uppercase version back to the variable.

  2. 2

    Show the original survives

    easy10 min

    Call a method without assigning and report the variable.

  3. 3

    Change one character

    easy10 min

    Rebuild the string with a capital first letter.

  4. 4

    Chain three methods

    easy10 min

    Trim, lowercase and replace in one chain.

  5. 5

    Build with an array

    medium10 min

    Collect the pieces and join them once.

Find the bug(5)

  1. 1

    Fix the result never assigned

    easy8 min

    The method returns a new string that was thrown away.

  2. 2

    Fix the character assignment

    easy8 min

    Assigning to a position is silently ignored.

  3. 3

    Fix the broken chain

    easy8 min

    Each method returns a new string, so the calls must be chained.

  4. 4

    Fix the push used on a string

    easy8 min

    Only an array can be pushed to, and join avoids a trailing separator.

  5. 5

    Fix the const reassignment attempt

    easy8 min

    A const cannot be reassigned, so use a new variable.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace