Grade 5 · lesson 2 of 4

Check an Input Before Using It

Reject values outside a stated whole-number input contract.

Download the grade pack

Supplied materials

  • Paper and pencil; an adult may read aloud. No device, account or purchase is needed.

Learn the idea

Validation asks whether an input meets the rules for being used. It is different from classifying a valid input. Our fictional page counter accepts whole numbers from 0 through 30 inclusive. Negative numbers, fractions and numbers above 30 receive invalid. We use supplied invented values, not records about a learner.

Algorithm: if pages is not a whole number from 0 through 30, show invalid; otherwise, if pages ≥ 10, show Goal reached; else show Keep going. Check validity first so an impossible 31-page input does not reach the goal branch. In this exercise, words and blank inputs are also invalid.

  1. Write the accepted range and whole-number rule.
  2. Make rows for −1, 0, 9, 10, 30, 31 and 2.5.
  3. Validate each value before applying the threshold.
  4. Record one final message for each row; do not classify rejected values.
Worked example

See the method in action

Rows: −1 → invalid; 0 → Keep going; 9 → Keep going; 10 → Goal reached; 30 → Goal reached; 31 → invalid; 2.5 → invalid. Both ends of the allowed range are included.

Your turn

Check your reasoning

Your answer is temporary and is not saved to an account. Download your current answer before leaving or reloading. Written work on paper or in another app stays in your own file.

Under this contract, what happens for pages = 30?

Feedback appears here after you check. This is practice, not a graded school assessment.

See the answer and explanation

Goal reached

30 is a whole number at the included upper end of the range and is at least 10. It is valid and gets Goal reached.

Take it further

Change the allowed range to 0 through 12, keeping the goal threshold 10. Test 12 and 13. Expected outputs: Goal reached and invalid.

Nothing here is saved to an account or sent to a teacher. The answer download includes your current choice and any checked feedback.

Check the subject sources

These LifeStarter passages, scenarios and exercises are authored for this Academy with AI assistance and review. External resources keep their publishers’ terms. A grade label suggests a starting level; it does not establish alignment with your school’s complete requirements.