The aim of this puzzle: Use a classic for loop to control exactly how many times a code block repeats.
Walkthrough of the solution: A classic for loop is used to repeat a block of code a specific number of times. A classic for loop has 3 components separated by semicolons:

1. A start condition that declares looping variable and gives it a value.
2. A test that keeps the classic for loop running as long as the test is true.
3. An update operation that changes the looping variable after each iteration (loop).

For example:

``````for (var i = 0; i < 10; i = 1 + 1) {
print(i)
}
``````
1. `var i = 0` sets up the looping variable `i` and gives it the value `0`.
2. `i < 10` is the test. The classic for loop will run as long as `i` is less than `10`.
3. `i = i + 1` updates the value of `i` after each iteration, adding `1` to the value each time.

In this puzzle, a classic for loop has been set up to repeat the code `print('nana')` a specific number of times. After the for loop has finished running, the code will print `'Batman!'` to the console.

To complete the puzzle, change the for loop’s test to `i < 8`, so that the code inside for loop is repeated 8 times.
Sample code solution:
(Tap below to reveal)

``````for (var i = 0; i < 8; i = i + 1) {
print('nana');
}
print('Batman!');
``````

JavaScript Concepts: Binary Expression (+), Code Block (for loop), Calling Functions, Identifiers, Loops, Variable Declaration
Grasshopper Concepts: print()

2 Likes