for...of Loops, online

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

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 ].

Discover other journeys with this module

What students will learn in this module

Every question in Module 23

Quick questions

  1. Does for...of loop through each value in an array?AYesBNo
  2. Does for...of require the keyword 'of'?AYesBNo
  3. Is 'in' the same as 'of' in this kind of loop?ANoBYes
  4. Does for...of need a variable name to hold each value?ANoBYes
  5. 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 does
for (let n of nums) { ... }Match it to what it does
Loops directly over each value in an arrayMatch it to what it does
Holds the current value during each pass of the loopMatch it to what it does
for (let n in nums) { ... }Match it to what it does
For (let n of nums) { ... }Match it to what it does

Fill in the blanks

  1. ___ (let fruit of fruits) {

    Hint: Type the keyword that starts a for loop.

  2. for (let fruit __ fruits) {

    Hint: Type the keyword that connects the variable to the array.

  3. ___ (let color of colors) {

    Hint: Type the keyword that starts a for loop.

  4. for (___ item of items) {

    Hint: Type the keyword used to declare the loop variable.

  5. 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]