Code Studio · Level 9
Game Engine Challenge
Create a tiny game object that changes score, stores items, and prints a final status.
Build your own game state.
Example code
class Game {
constructor(title) {
this.title = title;
this.score = 0;
this.items = [];
}
earn(item, points) {
this.items.push(item);
this.score += points;
}
finish() {
say(this.title + " complete!");
say("Score: " + this.score);
say("Items: " + this.items.join(" + "));
}
}
let game = new Game("Star Rescue");
game.earn("star", 10);
game.earn("key", 5);
game.finish();
Program result
PLAYER 1
SCORE 0
- Run your code to see output.
Type real JavaScript, then run it.
Game engine challenge complete.
You combined a class, methods, an array, and score changes into one mini game.
Next Lesson