Back to Rules Builder
Code Studio · Level 10

Game Rules Challenge

Create a rule that checks the player state and prints a different result for win or keep trying.

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

Write your own rule.

Example code
class Game {
  constructor(title) {
    this.title = title;
    this.score = 0;
    this.items = [];
  }

  earn(item, points) {
    this.items.push(item);
    this.score += points;
  }

  checkWin() {
    if (this.items.includes("star") && this.score >= 10) {
      say(this.title + " won!");
    } else {
      say("Keep playing.");
    }
  }
}

let game = new Game("Star Rescue");
game.earn("star", 10);
game.checkWin();
Output

Program result

Robot ready to speak your strings

Type real JavaScript, then run it.