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 trialBen Forrester
Courses Plus Student 5,357 PointsStill getting an error:
struct Person { let firstName: String let lastName: String
func getFullName () -> String {
return firstName + " " + lastName
}
}
made corrections but still complaining about not declaring a getFullName method. Works fine in the playground.
struct Person {
let firstName: String
let lastName: String
func getFullName () -> String {
return firstName + " " + lastName
}
}
3 Answers
jcorum
71,830 PointsApparently they want you to use String interpolation rather than concatenation:
func getFullName() -> String {
return "\(firstName) \(lastName)"
}
}
Travis McCormick
2,313 PointsHey Ben!
In the challenge description, it states "Declare a method named getFullName() that returns a string containing the personβs full name." So in this case, you literally have to return a string.
return "\(firstName) \(lastName)"
Your code it right, so don't feel discouraged. A lot of challenges have been very frustrating for me and I've realized that sometimes you have to read the challenge description very slowly to make sure you're not missing anything!
I hope this is helpful!
jcorum
71,830 PointsActually, isn't it the case that Ben is returning a String:
return firstName + " " + lastName
It's just that he's creating the String using String concatenation, while the editor wants him to use String interpolation.
:)
Travis McCormick
2,313 PointsHmm.. Now that I look at it, firstName
and lastName
are both of type String so the result will still be a string.
I remember having the same issue on this challenge, and when I finally tried changing it to the other format, the editor accepted it. I guess I just made the assumption.
Thanks for the clarification!