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
Store and read a value
easy10 minPut a score in a Map and read it back.
- 2
Count the entries
easy10 minReport how many entries the Map holds.
- 3
Use a number as a key
easy10 minStore a value under a numeric key and read it back.
- 4
Remove an entry
easy10 minDelete an entry and report whether it is still there.
- 5
Build from an array of pairs
medium10 minCreate a Map from pairs and read one value.
Find the bug(5)
- 1
Fix the object used for a numeric key
easy8 minAn object turns every key into a string.
- 2
Fix size called as a method
easy8 minsize is a property, not a method.
- 3
Fix bracket access on a Map
easy8 minA Map is read with get, not with square brackets.
- 4
Fix the flat array passed in
easy8 minA Map is built from pairs, not a flat list.
- 5
Fix delete used with the value
easy8 mindelete 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