Skip to main content

JavaScript Map — exercises and bug fixes

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

    Store and read a value

    easy10 min

    Put a score in a Map and read it back.

  2. 2

    Count the entries

    easy10 min

    Report how many entries the Map holds.

  3. 3

    Use a number as a key

    easy10 min

    Store a value under a numeric key and read it back.

  4. 4

    Remove an entry

    easy10 min

    Delete an entry and report whether it is still there.

  5. 5

    Build from an array of pairs

    medium10 min

    Create a Map from pairs and read one value.

Find the bug(5)

  1. 1

    Fix the object used for a numeric key

    easy8 min

    An object turns every key into a string.

  2. 2

    Fix size called as a method

    easy8 min

    size is a property, not a method.

  3. 3

    Fix bracket access on a Map

    easy8 min

    A Map is read with get, not with square brackets.

  4. 4

    Fix the flat array passed in

    easy8 min

    A Map is built from pairs, not a flat list.

  5. 5

    Fix delete used with the value

    easy8 min

    delete takes the key, not the value.

Ready to write the code?

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

Open the workspace