Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGirish Krishnan
5,237 PointsWhat am i missing here?
The task simply asks to create a struct named Dog, but the error shows it also needs a property 'numberOfLegs' of type String, which was never mentioned before. Is there something wrong with the task itself or is it my code? thx.
protocol AnimalType {
var numberOfLegs: Int { get }
}
protocol PetType: AnimalType {
var cuddlyName: String { get }
}
struct Dog: PetType {
}
1 Answer
Jennifer Nordell
Treehouse TeacherIt's odd that the error is saying you need String for numberOfLegs as it should be an int. The PetType is going to require a string with a "cuddlyName" (whatever that is). And because it inherits from AnimalType it's going to need a returned Int for the number of legs. See my code for clarification:
protocol AnimalType {
var numberOfLegs: Int { get }
}
protocol PetType: AnimalType {
var cuddlyName: String { get }
}
struct Dog: PetType {
var numberOfLegs: Int{ return 4 }
var cuddlyName: String{ return "Snookums" }
}
Girish Krishnan
5,237 PointsGirish Krishnan
5,237 PointsThanks Jennifer!
And the error asked for type Int, not String. That was a typo, sorry.