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.
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.
If you're having trouble with this exercise, here are some common mistakes and hints to help you out:
| Mistake | Hint |
|---|---|
| Using parentheses instead of square brackets | Arrays 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 names | Each 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 var | JavaScript is case-sensitive, so the casing (and spelling) must be exactly correct. |