for...of Loops, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
for...of Loops in one minute
What students need to know
This is exactly what a for...of loop does. fruit is the variable that stores each value as the loop runs.
for...of gives you each value in the array, one at a time. 'of' connects the loop variable to the array being looped over.
Mistakes students make
- 'for' is misspelled as 'Fr'.
- Use 'of', not 'in', to loop through array values.
- 'console' is misspelled as 'conssole'.
- The block must close with }, not ].
PREVIOUS · MODULE 22Arrays – Creation and Indexing
YOU ARE HERE · MODULE 23for...of Loops
NEXT · MODULE 24Arrays – Mutating Methods
What students will learn in this module
Every question in Module 23
Quick questions
- Does for...of loop through each value in an array?AYesBNo
- Does for...of require the keyword 'of'?AYesBNo
- Is 'in' the same as 'of' in this kind of loop?ANoBYes
- Does for...of need a variable name to hold each value?ANoBYes
- Must 'for' be written in lowercase?ANoBYes
Key terms
Students type the meaning of:
for...of
Match the pairs
for (let fruit of fruits) { ... }Match it to what it doesfor (let n of nums) { ... }Match it to what it doesLoops directly over each value in an arrayMatch it to what it doesHolds the current value during each pass of the loopMatch it to what it doesfor (let n in nums) { ... }Match it to what it doesFor (let n of nums) { ... }Match it to what it doesFill in the blanks
___ (let fruit of fruits) {Hint: Type the keyword that starts a for loop.
for (let fruit __ fruits) {Hint: Type the keyword that connects the variable to the array.
___ (let color of colors) {Hint: Type the keyword that starts a for loop.
for (___ item of items) {Hint: Type the keyword used to declare the loop variable.
for (let num of nums) _
Hint: Type the symbol that opens the loop's code block.
Spot the error
Question 1
AFr (let x of arr) {Bconsole.log(x);C}
Question 2
Alet arr = [1,2,3];Bfor (let x in arr) {Cconsole.log(x);D}
Question 3
Alet list = [1,2,3];Bfor (let v of list) {Cconssole.log(v);D}
Question 4
Alet nums = [1,2,3];Bfor (let n of nums) {Cconsole.log(n);D]
Question 5
Alet a = [1,2];Bfor (let x of a) {Cconsole.log(x);Dconsole.log("done");E]
