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 trialAhmet GULER
7,181 Pointsadding instance method
Hello,
I can't find out what am i doing wrong here.
Regards,
Ahmet
struct Person {
let firstName: String
let lastName: String
func getFullName (a: firstName, b: lastName) -> String {
return firstName+" "+lastName }
}
2 Answers
Keli'i Martin
8,227 PointsYou don't need to add parameters to the getFullName()
function. In fact, what you have written there is syntactically incorrect. Basically, what your function seems to be doing is passing a parameter a
that is of type firstName
, which is not a valid type. On top of that, you are not even using the parameters in the function at all.
All you need to do for that function is this:
func getFullName() -> String {
return firstName + " " + lastName
}
or even
func getFullName() -> String {
return "\(firstName) \(lastName)"
}
to use string interpolation to accomplish the same task.
Hope this helps!
Ahmet GULER
7,181 Pointsthanks a lot