OOP Studio Ages 9-15
Object Collections: Robo-Pet Roll Call
Put several objects in one array, then use one loop to command every pet.
CollectionAn array holds many objects.
LoopVisits each object once.
MethodEach pet runs
report().
What are you learning?
The three robo pets are separate objects stored together inside the pets array.
What is a loop for?
A loop repeats code for every item. One loop can command all the pets without writing Pixel, Bolt, and Zippy three separate times.
Where are loops used?
Games use loops for enemies, players, inventory items, projectiles, cards, pets, and anything else stored in a collection.
One array. Three robo pets.
let pets = [3 objects];
What happens?
The loop picks the next pet and calls the same method.
Choose a team command
Press Run and watch the loop visit every array slot.
The loop is ready.
pets[0]
Pixelenergy: 3
Pixelenergy: 3
pets[1]
Boltenergy: 5
Boltenergy: 5
pets[2]
Zippyenergy: 4
Zippyenergy: 4
petwaiting for the loop
Roll call results appear here.
Robo-Pet Parade unlocked!
You used one loop to command every object in the array.
Completed! Open Collection Builder