Back to Game Rules
Code Studio · Level 10

Rules Builder

Students add more rules for score, locked doors, and required items.

20-25 min Ages 9-12 Builder JavaScript
Code Editor

Build a locked-door rule.

Example code
class Player {
  constructor(name) {
    this.name = name;
    this.score = 0;
    this.inventory = [];
  }

  collect(item, points) {
    this.inventory.push(item);
    this.score += points;
  }

  canOpenDoor() {
    return this.inventory.includes("key") && this.score >= 10;
  }
}

let explorer = new Player("Nova");
explorer.collect("star", 10);
explorer.collect("key", 5);

if (explorer.canOpenDoor()) {
  say("Door unlocked!");
} else {
  say("Find the key and earn 10 points.");
}
Output

Program result

Robot ready to speak your strings

Type real JavaScript, then run it.