Give a Function an Input and Get a Result
Scenario
canBook checks whether the number of free seats is greater than zero.
- 1Pass the argument
- 2Evaluate the rule
- 3Return the value
Try it yourself
Follow the value through canBook(1).
| Case | State after the step |
|---|---|
| Pass the argument | — |
| Evaluate the rule | — |
| Return the value | — |
Reveal the explanation
- Pass the argument
The function receives 1.
- Evaluate the rule
1 is greater than 0. The comparison yields true.
- 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.
This browser could not save your progress. Changes last until you leave the page.