Curriculum

Curriculum

Give a Function an Input and Get a Result

Scenario

canBook checks whether the number of free seats is greater than zero.

  1. 1Pass the argument
  2. 2Evaluate the rule
  3. 3Return the value

Try it yourself

Follow the value through canBook(1).

Reveal the explanation
  1. Pass the argument

    The function receives 1.

  2. Evaluate the rule

    1 is greater than 0. The comparison yields true.

  3. Return the value

    The caller receives true.

Call the same function with 0. The rule is unchanged and the returned value is false.

Your turn

Trace the call canBook(0) and write what the caller can do with the result.

Common mistake Printing a value when the caller needs it returned.

Check your work

The caller receives false and can choose the decline branch.