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()

1 Like

Could you please clarify why we don’t need to create a variable “ingredient”? How the system knows that “ingredient” is what is inside var = recipe?
In other words, what if instead of “ingredient” I wrote “blablabla”. Would the below work:

for (var blablabla of recipe) {

Thank you!


Hey there, you actually are declaring a variable inside the for loop, and you are totally correct that you can name it whatever you want!

Let’s take a look at the example you posted:

var recipe = ['basil', 'olive oil', 'salt']

for (var blablabla of recipe) {

var blablabla is a variable declaration! This is the looping variable.
recipe is the array we want to loop through.

Together with the for and of keywords, this is telling the computer, "for every blablabla of the recipe array, print the blablabla"

The first time the loop iterates, blablabla has the value 'basil'. Then the line print(blablabla) runs and prints 'basil'.

On the next loop, blablabla has the value 'olive oil', and so when print(blablabla) runs it prints 'olive oil'.

Hope this helps! Let me know if you have any questions.


I believe this lesson has some bugs. Typing recipe for solution gives me wrong result but pressing recipe in your prewritten options give me ‘recipe’ without the 2 ’ and says correct. Why does me typing it differ also which is right recipe or ‘recipe’ during the coding. Also in the other example typing letter again gives me ’ and I get it wrong but choosing the ‘letter’ option gives me the right answer but it doesn’t have the ’ before and after the word. Which is right? Because in one example it has it and in the other it doesn’t. Please please explain

1 Like

I think, I know the problem, when you typed the recipe you might have typed it this way ‘recipe’ as a string with the quotation marks (’ ') … You are suppose to type it as recipe without the quotation marks … The instructions were to delete the string ‘list’, that’s entirely with it’s quotation marks…I hope this helps


For me i don’t understand what could be the problem I’ve tried all the way