Arrays are garden lists β store your koi fish & petals, then pick them by position! ππΈ
π― Missions
Add 3 koi fish to the pond using .push() today!
Use ALL 4 array skills: create [], index [0], .length, .push()
Solve all 5 garden challenges β no hints!
β β β pond.jsJavaScript
1
garden pondLIVE
Click βΆ Run to see your garden pondβ¦
πΈ Garden Puzzle Step 1 of 5
Create a fish array with 3 koi names and print it!
π‘ Hint:Declare: var fish = ["Kohaku", "Sanke", "Ogon"]; then console.log(fish);
πΈ Array Adventure
In Lesson 13 you mastered strings β single pieces of text. Today in the πΈ Cherry Blossom Garden, you'll learn to store lists of things! A list in JavaScript is called an array. Imagine a pond full of koi fish, or a branch full of petals β arrays let you keep them all together, pick any one by its position, count them, and add new ones. Let's tend the garden with code!
πΈ Array Toolkit
var fish = ["A", "B", "C"];β create an array (a list)
fish[0]β "A" (first item β index starts at 0!)
fish.lengthβ 3 (count how many items)
fish.push("D")β adds "D" to the end of the list
fish[fish.length - 1]β always gets the LAST item
π¦Arrays store lists: ["red", "blue", "green"] β items go inside [ ]
π’Index picks an item: fish[0] gets the 1st, fish[1] gets the 2nd. Starts at 0!
π.length counts items: fish.length β how many are in the array
β.push() adds to the end: fish.push("new") makes the list longer
πΈArrays hold strings, numbers, or any mix β they're the most useful tool in coding!
π Garden Master!
You just mastered arrays β the most important data structure in programming! Your code can now store lists of anything, grab items by position, count them, and grow them. Every app you've ever used stores data in arrays: your messages, your photos, your game inventory β all arrays!
π What you learned
var list = ["a", "b", "c"] β create an array (a list of values)
list[0] β access items by index (counting starts at 0!)
list.length β count how many items are in the array
list.push("new") β add a new item to the end
Arrays can hold strings, numbers, or any mix of values
π Tomorrow: Loop Master β teach your code to repeat actions and visit every item in your arrays automatically! π