Follow the Recipe Explainer


Aim of the puzzle: Use a For…of loop to iterate through an array.
Walk through of solution: A For…of loop is one of several ways to iterate through an array in javascript. The For…of loop declares a looping variable, and then loops through each element in an array, with the looping variable referring to the current element at each iteration. For example:

for (var letter in englishAlphabet) {

The above For…of loop declares the variable letter and iterates through the englishAlphabet array. Each time it iterates (loops), letter refers to the current element in the array. On the first iteration, letter has the value 'a'. On the 2nd loop, letter has the value 'b'.

In this puzzle, a For…of loop is used to iterate through the recipe array. The looping variable ingredient will refer to the current element in recipe as the for loop iterates through the array.

To complete the puzzle, delete the string 'list' from the for loop, and replace it with the identifier recipe.

Sample code solution:

var recipe = [
    'olive oil',
for (var ingredient of recipe) {

Javascript Concepts: Calling Functions, For Loop, Variable Declarations, Data Structures (arrays)
Grasshopper Concepts: print()