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 trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![edward watson](https://secure.gravatar.com/avatar/0859bf8f96774fec84bd762c6efc3b50?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
edward watson
354 PointsHelp with function method
I'm having issues with the exercise. The previous exercise on functions does not go over some of the function specifics that are used in this object lesson so i'm a little confused about how to specify my function. I don't understand how my function should return the name? For instance, in a previous lesson on functions we used print to create the output. Here we are specifying a return type as a custom type, which is necessary for this method?
struct Person {
let firstName: String
let lastName: String
func fullname(firstname: String = "Ed", lastname: String = " Watson") -> [Person] {
}
}
4 Answers
![Steve Hunter](https://uploads.teamtreehouse.com/production/profile-photos/806282/micro_Ironman.jpg)
Steve Hunter
57,712 PointsHi Edward,
Your method doesn't need to take any parameters as it can access the two member variables directly. It wants to return the representation of the full name, which is of String datatype.
I'd use interpolation inside the method to return "\(firstName) \(lastName)"
. You could concatenate, adding a space in between, if you prefer.
So, create your method, state no parameters, make it return a string and use the above line inside the method - that should work.
Let me know how you get on.
Steve.
![edward watson](https://secure.gravatar.com/avatar/0859bf8f96774fec84bd762c6efc3b50?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
edward watson
354 Pointsthis doesn't work:
struct Person {
let firstName: String
let lastName: String
func fullName(firstname: String, lastname: String) -> String {
return firstName + " " + lastName
}
}
[MOD: edited code block - srh]
![Steve Hunter](https://uploads.teamtreehouse.com/production/profile-photos/806282/micro_Ironman.jpg)
Steve Hunter
57,712 PointsHi Edward,
If you get rid of the parameters that you are requiring the function to receive, that will probably work.
So, lose what's inside the parentheses, but leave the parentheses in place. Your method doesn't need to receive firstName
or lastName
because it is within the class and can see them directly.
The rest looks fine.
Keep me posted how you get on.
Steve.
![edward watson](https://secure.gravatar.com/avatar/0859bf8f96774fec84bd762c6efc3b50?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
edward watson
354 Pointsexcellent that works. thanks
![Steve Hunter](https://uploads.teamtreehouse.com/production/profile-photos/806282/micro_Ironman.jpg)
Steve Hunter
57,712 PointsNo problem!