Robots Love Rainbows

Lesson 3: Arrays

In programming, an array is a special type of variable that can store multiple values instead of just one. Think of it like a list or a row of boxes, where each box holds a piece of data. Arrays are useful when we need to keep track of many things at once, like a list of names, numbers, or colors.

Example

Here’s an example of an array in JavaScript. This code contains a series of strings that could refer to people's names.
This array contains three names. Each color is written inside quotation marks (since they are strings, just as you learned in Lesson 1), and they are separated by commas inside square brackets. All arrays use this structure, no matter what type of data they store.

Your Task

In Lesson 1, we made the ball light up with one color. In this lesson, you can provide an array of colors through which the ball will cycle. Write JavaScript code to create an array named colors that contains at least three different colors of your choice. See this page for a list of colors to choose from.

Hints

If you're having trouble with this exercise, here are some common mistakes and hints to help you out:

MistakeHint
Using parentheses instead of square bracketsArrays must be created with [ ], not ( ). Example: var colors = ["red", "green", "blue"];
Forgetting to use var when declaring the variable, like delay = 2000;Always use var when declaring a variable for the first time. You might find other resources telling you to use let or const but we need to use var for the automated system to work.
Forgetting to use quotation marks around color namesEach color is a string, so it must be inside quotation marks. Example: var colors = ["red", "green", "blue"];
Misspelling or using the wrong case for the variable name or for varJavaScript is case-sensitive, so the casing (and spelling) must be exactly correct.