Maps – Basics, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
Maps – Basics in one minute
What students need to know
get() looks up the value stored for the "Sam" key. set() stores 30 under the key "Tom" in the ages Map.
new Map() creates an empty Map ready to store key-value pairs. set() stores a value under the given key in the Map.
Mistakes students make
- 'Map' must start with a capital M, not lowercase.
- 'set' must be lowercase - a capital S causes an error.
- 'get' must be lowercase - a capital G causes an error.
PREVIOUS · MODULE 50OOP – Inheritance (extends)
YOU ARE HERE · MODULE 51Maps – Basics
NEXT · MODULE 52Sets – Basics
What students will learn in this module
Every question in Module 51
Quick questions
- Does new Map() create a new Map object?AYesBNo
- Does set() add a key-value pair to a Map?ANoBYes
- Does get() read a value from a Map using its key?AYesBNo
- Is 'map' with a lowercase m valid for creating a Map?AYesBNo
- Must 'set' be written in lowercase?AYesBNo
Key terms
Students type the meaning of:
new Map()
Match the pairs
new Map()Match it to what it doesscores.set("Sam", 90)Match it to what it doesReads the value stored under a given keyMatch it to what it doesAdds a new key-value pair to a MapMatch it to what it doeslet m = new map();Match it to what it doesm.Set("a", 1);Match it to what it doesFill in the blanks
let scores = ___ Map();
Hint: Type the keyword used to create a new Map.
scores.___("Sam", 90);Hint: Type the method that adds a key-value pair to a Map.
console.log(scores.___("Sam"));Hint: Type the method that reads a value from a Map by its key.
let ages = ___ Map();
Hint: Type the keyword used to create a new Map.
ages.___("Tom", 30);Hint: Type the method that adds a key-value pair to a Map.
Spot the error
Question 1
Alet m = new map();Bm.set("a", 1);Cconsole.log(m);
Question 2
Alet m2 = new Map();Bm2.Set("b", 2);Cconsole.log(m2);
Question 3
Alet m3 = new Map();Bm3.set("c", 3);Cconsole.log(m3.Get("c"));
Question 4
Alet a = 1;Blet b = 2;Clet m5 = new map();
Question 5
Alet m6 = new Map();Bm6.set("d", 4);Cconsole.log(m6);Dm6.Set("e", 5);
