Decide What Happens on Invalid Input
Scenario
Policy for our booking checker: negative freeSeats or non-integer values must return/raise an invalid-input error rather than silently returning false.
Try it yourself
Compare each input against the stated invalid-input policy.
| Case | Result |
|---|---|
| freeSeats = 0 | Select a choice above to see what happens. |
| freeSeats = -2 | Select a choice above to see what happens. |
| freeSeats = "2" (text instead of integer) | Select a choice above to see what happens. |
Reveal the explanation
- freeSeats = 0
Valid boundary → returns false (room is full, not an error).
- freeSeats = -2
Invalid input → raises/returns INVALID_FREE_SEATS error per policy.
- freeSeats = "2" (text instead of integer)
Invalid input → raises/returns INVALID_FREE_SEATS error; do not coerce silently.
Distinguishing a valid "decline" (0 seats) from an "invalid input" (-2 seats) helps callers show the right message and keeps tests unambiguous across languages.
Download shared test cases
Your turn
Write a one-line invalid-input policy for the Classroom Quiz Scorer when answer length differs from key length, plus one example case.
Common mistake Writing an expected output for invalid input without first declaring whether invalid input returns an error or a fallback value.
Check your work
A stated policy ("unequal lengths return INVALID_LENGTH error") paired with key [A,B,C] and answers [A,B] → INVALID_LENGTH.
Quick check
This browser could not save your progress. Changes last until you leave the page.