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)
![Brent Caswell](https://secure.gravatar.com/avatar/5aaf76b896cb91e2f5f106edec50a689?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Brent Caswell
5,343 PointsHaving trouble with this code challenge
Hey, I’ve added a function to the structure which should be able to concatenate the firstName and lastName strings, but I’m getting an error saying that I haven’t added a function to the structure. Please advice!
struct Person {
let firstName: String
let lastName: String
func fullName(firstName: String, lastName: String) -> String {
let results = "\(firstName) \(lastName)"
return results
}
}
1 Answer
![andren](https://secure.gravatar.com/avatar/229e60726cd92951c31d7303e40be2cd?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
andren
28,558 PointsThe challenge asks you to add a fullName
method, but it does not ask you to take add any parameters to the method. The firstName
and lastName
that the method should concatenate are the ones that already exists within the Person
struct
. Since the method is also inside that struct
it can access them directly without being passed any data.
Like this:
struct Person {
let firstName: String
let lastName: String
func fullName() -> String { // Declare fullName method with no parameters
let results = "\(firstName) \(lastName)" // Return `firstName` and `lastName` from struct
return results
}
}