JavaScript Map Methods — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Map Methods 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
List the keys
easy10 minSpread the keys into an array and join them.
- 2
Total the values
easy10 minAdd up every value in the Map.
- 3
Loop with forEach
easy10 minBuild a line using the value and the key.
- 4
Convert to an object
easy10 minTurn the Map into a plain object and read a property.
- 5
Convert from an object
medium10 minBuild a Map from an object and read a value.
Find the bug(5)
- 1
Fix the forEach arguments swapped
easy8 minIn a Map forEach the value comes first, then the key.
- 2
Fix map called on the iterator
easy8 minkeys returns an iterator, which has no array methods.
- 3
Fix keys totalled instead of values
easy8 minThe numbers are the values, not the keys.
- 4
Fix the Map spread directly into an object
easy8 minObject.fromEntries is what converts the pairs.
- 5
Fix the object passed straight to Map
easy8 minA Map needs pairs, which Object.entries produces.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace