Skip to main content

JavaScript Type Coercion — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Type Coercion 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

    See plus join

    easy10 min

    Report what a string plus a number gives.

  2. 2

    See minus convert

    easy10 min

    Report what a string minus a number gives.

  3. 3

    Watch the order matter

    easy10 min

    Report the result of 1 plus 2 plus the text 3.

  4. 4

    Convert a boolean

    easy10 min

    Report what true plus one gives.

  5. 5

    Avoid the surprise

    medium10 min

    Convert before adding so the answer is arithmetic.

Find the bug(5)

  1. 1

    Fix the accidental join

    easy8 min

    The values are being joined instead of added.

  2. 2

    Fix the order of operations

    easy8 min

    The numbers should be added before the text is joined.

  3. 3

    Fix the total built as text

    easy8 min

    Starting with an empty string joins every number.

  4. 4

    Fix the boolean used as text

    easy8 min

    The boolean should be counted as a number.

  5. 5

    Fix the comparison of mixed types

    easy8 min

    Convert the text before comparing it as a number.

Ready to write the code?

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

Open the workspace