Code Studio · Level 12
Capstone Builder
Students customize the final game title, goal items, score values, and ending message.
Customize the final project.
Example code
class MiniGame {
constructor(title, requiredItem) {
this.title = title;
this.requiredItem = requiredItem;
this.score = 0;
this.items = [];
}
collect(item, points) {
this.items.push(item);
this.score += points;
say("+" + points + " for " + item);
}
hasWon() {
return this.items.includes(this.requiredItem) && this.score >= 15;
}
report() {
say("Game: " + this.title);
say("Items: " + this.items.join(", "));
say("Score: " + this.score);
say(this.hasWon() ? "You win!" : "Try one more quest.");
}
}
let game = new MiniGame("Moon Garden", "moon seed");
game.collect("map", 5);
game.collect("moon seed", 10);
game.report();
Program result
- Run your code to see output.
Type real JavaScript, then run it.
Capstone builder complete.
You customized a mini game with objects, arrays, methods, score, and a win rule.
Try Capstone Challenge