Maps – Basics, online

Six activities your students do on their own devices. See who's finished, and their scores.

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.

Discover other journeys with this module

What students will learn in this module

Every question in Module 51

Quick questions

  1. Does new Map() create a new Map object?AYesBNo
  2. Does set() add a key-value pair to a Map?ANoBYes
  3. Does get() read a value from a Map using its key?AYesBNo
  4. Is 'map' with a lowercase m valid for creating a Map?AYesBNo
  5. 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 does
scores.set("Sam", 90)Match it to what it does
Reads the value stored under a given keyMatch it to what it does
Adds a new key-value pair to a MapMatch it to what it does
let m = new map();Match it to what it does
m.Set("a", 1);Match it to what it does

Fill in the blanks

  1. let scores = ___ Map();

    Hint: Type the keyword used to create a new Map.

  2. scores.___("Sam", 90);

    Hint: Type the method that adds a key-value pair to a Map.

  3. console.log(scores.___("Sam"));

    Hint: Type the method that reads a value from a Map by its key.

  4. let ages = ___ Map();

    Hint: Type the keyword used to create a new Map.

  5. 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);