Back to Polymorphism Builder
OOP Studio Ages 9-15

Polymorphism Challenge

Repair three activate() overrides, then run one command through an enchanted room.

10-15 min Ages 9-15 OOP Challenge JavaScript
Mission

Match each room object with the behavior its activate() method should perform.

Important

The loop may only call object.activate(). Do not add type-checking if statements.

Proof

Correct overrides produce three different animations and sounds from one method name.

Repair the Overrides

What should each activate() method do?

Closed wooden cave door
Door.activate()
Locked treasure chest
TreasureChest.activate()
Closed floor spike trap
Trap.activate()
let roomObjects = [door, chest, trap];

for (let object of roomObjects) {
  object.activate();
}
Enchanted Room

One command. Three object behaviors.

Closed wooden cave door
Doorwaiting
Locked treasure chest
Treasure Chestwaiting
Closed floor spike trapFired foam dart
Trapwaiting
Room loop ready

Repair all three overrides, then activate the room.