Model Shapes with Unions
Talk it through with a coach who asks guiding questions and gives hints until you reach the answer. Pass to mark the challenge as completed.
The problem
- easy
- Pro
An app draws circles, which have a radius, and rectangles, which have a width and a height. Explain how you'd type a shape so that a function computing the area can only read the fields that exist for each kind, and so the compiler warns you if someone adds a triangle and forgets to handle it.
Talk this problem through with an AI coach
This is a Pro challenge. Sign in with Google, then upgrade to start a voice session.