Back to State Builder
OOP Studio Ages 9-15

State Challenge

Create a class with one property that changes when a method runs, then call the method twice.

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

Create your own state change.

Example code
class GameCharacter {
  constructor(name) {
    this.name = name;
    this.health = 5;
  }

  takeHit() {
    this.health -= 1;
    say(this.name + " health: " + this.health);
  }
}

let hero = new GameCharacter("Nova");
hero.takeHit();
hero.takeHit();
Output

Program result

Robot ready to speak your strings

Type real JavaScript, then run it.