Skip to main content

JavaScript Data Types — exercises and bug fixes

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

    Report a number's type

    easy10 min

    Use typeof to show the type of the value 7.

  2. 2

    Report a string's type

    easy10 min

    Use typeof to show the type of "hello".

  3. 3

    Convert a string to a number

    easy10 min

    Turn the string "25" into a number and add 5 to it.

  4. 4

    Convert a number to a string

    easy10 min

    Turn 99 into a string and show its length.

  5. 5

    Check for an array

    medium10 min

    Show whether [1,2,3] is an array, as true or false.

Find the bug(5)

  1. 1

    Fix the string addition

    easy8 min

    Adding two numeric strings joins them instead of summing them.

  2. 2

    Fix the typeof check on an array

    easy8 min

    This reports "object" instead of confirming an array.

  3. 3

    Fix the wrong equality

    easy8 min

    Loose equality makes this comparison true when it should be false.

  4. 4

    Fix the undefined property read

    easy8 min

    Reading a missing property shows undefined instead of the count.

  5. 5

    Fix the number that became text

    easy8 min

    The total is joined as text because one value is a string.

Ready to write the code?

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

Open the workspace