Back to Real Classes
Code Studio · Level 8

Class Builder

Students add a method to a class and create more than one object from the same blueprint.

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

Build two characters.

Example code
class Character {
  constructor(name, tool, level) {
    this.name = name;
    this.tool = tool;
    this.level = level;
  }

  showCard() {
    say(this.name + " carries a " + this.tool);
    say("Level " + this.level);
  }
}

let nova = new Character("Nova", "debug wand", 3);
let milo = new Character("Milo", "loop boots", 4);

nova.showCard();
milo.showCard();
Output

Program result

Robot ready to speak your strings

Type real JavaScript, then run it.