The aim of this puzzle: Build a band-name generator that outputs at least 9 different band name options.
Walkthrough of the solution: This puzzle features a “nested” for loop, which is a for loop inside another for loop.
For each iteration of the outer for loop, the inner for loop iterates completely. For example:
for (var a of [0, 1]) {
for (var b of [0, 1, 2]) {
print(a, b);
}
}
When the code runs, this will print:
0,0
0,1
0,2
1,0
1,1
1,2
In this puzzle, we will use a nested for loop to generate band names. To complete the puzzle, add 2-3 adjectives to the outer for loop’s array, and 2-3 nouns to the inner for loop’s array.
Sample code solution:
(Tap below to reveal)
for (var adj of ['Buggy', 'Null', 'Void', 'Undefined']) {
for (var noun of ['Functions', 'Object', 'Breakpoints', 'Undefined']) {
print ('The ' + adj + ' ' + noun);
}
}
JavaScript Concepts: Data Structures (Arrays), Code Block (for loop), Loops, Variable Declaration, Binary Expression (+), Calling Functions, Identifiers
Grasshopper Concepts: print()