Sets – Basics, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
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
What students will learn in this module
Every question in Module 52
Quick questions
- Does new Set() create a new Set object?ANoBYes
- Does add() add a value to a Set?AYesBNo
- Does a Set automatically remove duplicate values?ANoBYes
- Is 'set' with a lowercase s valid for creating a Set?ANoBYes
- 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 doesnums.add(1)Match it to what it doesAutomatically removes duplicate values from a collectionMatch it to what it doesInserts a value into a SetMatch it to what it doeslet s = new set();Match it to what it doess.Add(1);Match it to what it doesFill in the blanks
let nums = ___ Set();
Hint: Type the keyword used to create a new Set.
nums.___(1);
Hint: Type the method that adds a value to a Set.
let colors = ___ Set();
Hint: Type the keyword used to create a new Set.
colors.___("red");Hint: Type the method that adds a value to a Set.
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);
