Spread the keys into an array and join them.
Acceptance criteria
- 1.#out should show Ada,Grace.
JavaScript Tutorial · JavaScript Map & Set
These 10 tasks go with the JavaScript Map Methods chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Map methods let you loop over entries and convert to and from other structures.” .
1.List the keysexercise · easy · 10 min
Spread the keys into an array and join them.
Passes when: #out should show Ada,Grace.
2.Total the valuesexercise · easy · 10 min · practice plan
Add up every value in the Map.
Passes when: #out should show 185.
3.Loop with forEachexercise · easy · 10 min · practice plan
Build a line using the value and the key.
Passes when: #out should show Ada scored 90.
4.Convert to an objectexercise · easy · 10 min · practice plan
Turn the Map into a plain object and read a property.
Passes when: #out should show 90.
5.Convert from an objectexercise · medium · 10 min · practice plan
Build a Map from an object and read a value.
Passes when: #out should show dark.
6.Fix the forEach arguments swappedbug fix · easy · 8 min
In a Map forEach the value comes first, then the key.
Passes when: #out should show Ada scored 90.
7.Fix map called on the iteratorbug fix · easy · 8 min · practice plan
keys returns an iterator, which has no array methods.
Passes when: #out should show Ada,Grace.
8.Fix keys totalled instead of valuesbug fix · easy · 8 min · practice plan
The numbers are the values, not the keys.
Passes when: #out should show 185.
9.Fix the Map spread directly into an objectbug fix · easy · 8 min · practice plan
Object.fromEntries is what converts the pairs.
Passes when: #out should show 90.
10.Fix the object passed straight to Mapbug fix · easy · 8 min · practice plan
A Map needs pairs, which Object.entries produces.
Passes when: #out should show dark.
Between them these tasks cover keys and values, forEach and Conversion.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.