Code Studio · Level 10
Game Rules
Write the rulebook. Conditional rules decide who wins, who keeps playing, and who still needs the key — your code is the referee.
Check a win rule.
Example code
class Player {
constructor(name) {
this.name = name;
this.items = [];
}
collect(item) {
this.items.push(item);
}
hasItem(item) {
return this.items.includes(item);
}
}
let player = new Player("Bolt");
player.collect("star");
if (player.hasItem("star")) {
say("Mission complete!");
} else {
say("Keep searching for the star.");
}
Program result
- Run your code to see output.
Type real JavaScript, then run it.
Game rule ran.
You used a class, an array, and an if statement to check a win condition.
Open Rules Builder