Curriculum

Curriculum

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.

Selected choicePick a choice below
Result—

Try it yourself

Compare each input against the stated invalid-input policy.

Reveal the explanation
  1. freeSeats = 0

    Valid boundary → returns false (room is full, not an error).

  2. freeSeats = -2

    Invalid input → raises/returns INVALID_FREE_SEATS error per policy.

  3. 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

Why should freeSeats = 0 and freeSeats = -1 be treated differently when the contract requires explicit invalid-input errors?
Show the answer and reasoning

Correct answer 0 is a valid full room (false), whereas -1 is impossible data (error)

A full room is a normal business state; a negative seat count indicates corrupted or invalid input.