The aim of this puzzle: Create a list (an array) of things an owl might do at midnight, then randomly select one and print it out.
Walkthrough of the solution: The variable
word should hold a list (an array
) rather than a single word. To replace the string with an array, tap on
'quacks' to highlight it (you should still see the little keyboard icon) and then tap the array key
. Once you’ve created the array, you put items inside of it. For this puzzle, it should store strings. Use the
str key to add two different strings to the array.
You also need to randomly pick an item from the array and there are two different ways to do this! You can use the
pickRandom() function when you reference the
word variable in the print statement, to make something that looks like
print('the owl ' + pickRandom(word) + ' at midnight') OR you could pick the random thing while you’re creating the variable, by putting the array inside the function, like
var word = pickRandom(['quacks', 'hoots', 'dances']).
Sample code solution:
(Tap below to reveal)
var word = pickRandom([ 'hoots', 'quacks', 'howls', 'dances' ]); print('the owl ' + word + ' at midnight');
Grasshopper Concepts: pickRandom(), print()