The aim of this puzzle: Create a red box by getting the color from an array.
Walkthrough of the solution: The beginning of the code creates an array called
colors which just contains 4 strings:
'yellow' is the 0th item in the
colors array and
'blue' is the 1st item in the
You’re able to choose a specific item from an array using the item’s index which is just a number.
Since you want a red box, you want to get the item at index 2 by using
colors. Now that you know how to access the
'red' item in the array, you want to use it to draw a redbox – simply put it inside of
drawBox(). That means
drawBox(colors) will draw a redbox (as long as you don’t change the
Sample code solution:
(Tap below to reveal)
var colors = [ 'yellow', 'blue', 'red', 'green' ]; drawBox(colors);