Back to Debugging Game Rules
Code Studio · Level 11

Debug Builder

Students compare expected and actual results so they can find mistakes in rules.

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

Compare expected results.

Example code
function canOpenDoor(items, score) {
  return items.includes("key") && score >= 10;
}

function testRule(name, actual, expected) {
  if (actual === expected) {
    say(name + ": pass");
  } else {
    say(name + ": fix this rule");
  }
}

testRule("has key and 10 points", canOpenDoor(["key"], 10), true);
testRule("missing key", canOpenDoor(["star"], 10), false);
testRule("not enough points", canOpenDoor(["key"], 5), false);
Output

Program result

Robot ready to speak your strings

Type real JavaScript, then run it.