Back to Collection Builder
OOP Studio Ages 9-15

Collection Challenge

Create an array with at least three objects, then use a loop to call one method on every object.

10-15 min Ages 9-15 OOP Challenge JavaScript
Code Editor

Create your own object team.

Example code
class PowerUp {
  constructor(name, points) {
    this.name = name;
    this.points = points;
  }

  activate() {
    say(this.name + " gives " + this.points + " points");
  }
}

let powerUps = [
  new PowerUp("Star", 10),
  new PowerUp("Shield", 5),
  new PowerUp("Key", 3)
];

for (let powerUp of powerUps) {
  powerUp.activate();
}
Output

Program result

Robot ready to speak your strings

Type real JavaScript, then run it.