Tell Cats from Dogs by Their Properties
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Export a Cat type (a name and a number of lives) and a Dog type (a name and a breed); they share no tag field, so tell them apart with the in operator. Write speak(pet), which returns Meow for a cat and Woof for a dog, and introduce(pet), which returns Tom the cat (9 lives) or Rex the beagle. Type speak so its result follows the pet: Meow for a Cat, Woof for a Dog, either for a pet that could be both, and anything that is neither is a type error.
Your code must pass
- Cats meow and dogs woof
- Introduces each pet
- Has no type errors
- speak returns Meow for a Cat and Woof for a Dog
- speak returns either sound for any pet
- Rejects something that's neither