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 trialfaraidonhwe
Courses Plus Student 4,016 Points"Double check the implementation of the overridden method to match the directions specified" whats wrong
cant undertand why my code isint working
class Person {
let firstName: String
let lastName: String
init(firstName: String, lastName: String) {
self.firstName = firstName
self.lastName = lastName
}
func fullName() -> String {
return "\(firstName) \(lastName)"
}
}
// Enter your code below
class Doctor: Person {
override init(firstName: String, lastName: String) {
super.init(firstName : firstName, lastName : lastName)
}
override func fullName() -> String {
return "Dr \(lastName)"
}
}
let someDoctor = Doctor(firstName: "Sam", lastName: "Smith")
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHi there,
Where you get an error like "Double check the implementation of the overridden method to match the directions specified" it means your code is likely correct in syntax, but it is not following the instructions laid out.
Challenges are very strict and specific in the instructions, and they must be followed explicitly in order for the task to pass.
Here, there are two issues:
First, the instructions say to override "the fullname()
method", but you are also overriding the init()
method, which was not asked for, and is not needed as the Doctor
class inherits from the Person
class and the Person
class already has the proper init()
. So, you need to delete the overriding of the init()
.
Second, the instructions say to output (for example) "Dr. Smith". ** Notice the period after "Dr"? This is missing in your string. And, yes, this missing puncuation will result in a Bummer
.
Once those errors are fixed up, the challenge will pass.
But really nice work on the methods!! Just remember, if the instructions don't ask for it... don't do it.
Keep coding! :)
faraidonhwe
Courses Plus Student 4,016 PointsThanks Jason. Who would have thought it was all because of a period"."
Great tip "if the instructions don't ask for it... don't do it. " - this is gold