NOTE: Learners are first introduced to arrays in the world of Asteroidia. To learn more about arrays and other concepts, check out the full learning guide for Asteroidia --> click HERE

Variables store information, or values, in a program. There are different types of variables that are used in different situations: strings, integers, and arrays.

Strings are groups of characters, like words or phrases, and integers are whole numbers, like 5, 50, or 500. But what if we want to store multiple values in a variable? The solution is an Array!

Definition: an array is an ordered list of related items that can include any type of value, including Strings and Integers.

In real life: In real life, you can think of your closet as an array- you use your closet to organize your clothes and keep them in a specific order. The order you hang your clothes in organizes them in a defined way- your shirts are going to stay where you hang them, and you remove a shirt, the order of the rest of the shirts won't be changed.

Each value in an array has an index number, which marks the exact position of the value in the array. This index is critical for finding and storing values, since an array can have hundreds or thousands of items! 

The first value in an array has an index of 0. If your yellow shirt is the first item in your closet, it will be at located at index 0.

In Programming: In programming, we can store related data in an array.

In Kodable, learners independently practice using arrays to clear the asteroid field. Arrays in the world of Asteroidia work like they do in programming. Learners can use an array to store multiple values, achieving three moves with just one command. This allows students to solve some levels in just one move.

In this lesson, the colors represent string variables and the numbers represent integers. There are two string values (red and yellow) and one integer value (2). I need to correctly order my list of variables in the command bin to be able to clear the asteroid field when I match the values: First, yellow needs to clear. Then, 2. Finally, red. The values must be stored in the variable in the correct sequence for the learner to successfully clear the asteroid field.

Why We Use Arrays: Arrays make storing and finding values easier and efficient. Programmers can use one command to search all of the values stored in one array, without needing to know what each variable may be.

Did this answer your question?