Sets – Basics, online

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

Sets – Basics in one minute

What students need to know

A Set only ever keeps one copy of each unique value. add() stores "red" in the colors Set.

new Set() creates an empty Set ready to store unique values. add() inserts the given value into the Set.

Mistakes students make

  • 'Set' must start with a capital S, not lowercase.
  • 'add' must be lowercase - a capital A causes an error.
  • This line is actually correct - adding a duplicate just has no effect.
PREVIOUS · MODULE 51Maps – Basics
YOU ARE HERE · MODULE 52Sets – Basics

Discover other journeys with this module

What students will learn in this module

Every question in Module 52

Quick questions

  1. Does new Set() create a new Set object?ANoBYes
  2. Does add() add a value to a Set?AYesBNo
  3. Does a Set automatically remove duplicate values?ANoBYes
  4. Is 'set' with a lowercase s valid for creating a Set?ANoBYes
  5. Must 'add' be written in lowercase?AYesBNo

Key terms

Students type the meaning of:

  • new Set()

Match the pairs

new Set()Match it to what it does
nums.add(1)Match it to what it does
Automatically removes duplicate values from a collectionMatch it to what it does
Inserts a value into a SetMatch it to what it does
let s = new set();Match it to what it does
s.Add(1);Match it to what it does

Fill in the blanks

  1. let nums = ___ Set();

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

  2. nums.___(1);

    Hint: Type the method that adds a value to a Set.

  3. let colors = ___ Set();

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

  4. colors.___("red");

    Hint: Type the method that adds a value to a Set.

  5. nums.___(2);

    Hint: Type the method that adds a value to a Set.

Spot the error

Question 1

Alet s = new set();Bs.add(1);Cconsole.log(s);

Question 2

Alet s2 = new Set();Bs2.Add(2);Cconsole.log(s2);

Question 3

Alet s3 = new Set();Bs3.add(3);Cs3.add(3);

Question 4

Alet a = 1;Blet b = 2;Clet s5 = new set();

Question 5

Alet s6 = new Set();Bs6.add(4);Cconsole.log(s6);Ds6.Add(5);