Skip to main content

JavaScript Truthy and Falsy — exercises and bug fixes

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

    Test a non-empty string

    easy10 min

    Report whether a piece of text is truthy.

  2. 2

    Test an empty array

    easy10 min

    Report that an empty array is still truthy.

  3. 3

    Check a list properly

    easy10 min

    Use length to find out whether the array is empty.

  4. 4

    Test the string zero

    easy10 min

    Report whether the text zero is truthy.

  5. 5

    Convert deliberately

    medium10 min

    Use Boolean to report the truthiness of an empty string.

Find the bug(5)

  1. 1

    Fix the empty array check

    easy8 min

    An empty array is truthy, so length must be checked.

  2. 2

    Fix the zero treated as missing

    easy8 min

    A count of zero is valid and should be reported.

  3. 3

    Fix the empty object check

    easy8 min

    An empty object is truthy, so its keys must be counted.

  4. 4

    Fix the string zero assumed falsy

    easy8 min

    The text zero is truthy, unlike the number.

  5. 5

    Fix the valid zero rejected

    easy8 min

    A guest id of zero is valid, but a truthy check treats it as missing.

Ready to write the code?

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

Open the workspace