Course of Raku / Advanced / Control flow / given and when / Exercises

Life stage from age

Problem

Using given/when, print the life stage for a hard-coded age according to these bands:

  • child for 0–12,
  • teenager for 13–19,
  • adult for 20–64,
  • senior for 65 and above.

A negative age makes no sense, so print invalid for any number below zero. Make sure that case is handled before the range checks.

Example

For the age 30, the program prints:

adult

Solution

See the solution

Course navigation

Quiz — when   |   Solution: Life stage from age