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 trialMatt Conway
1,572 PointsMethods
Not sure what codes I am doing wrong
Challenge Task 1 of 2
Given the struct below in the editor, we want to add a method that returns the personโs full name. Declare a method named getFullName() that returns a string containing the personโs full name. Note: Make sure to allow for a space between the first and last name
/Users/mattconway/Desktop/Screen Shot 2016-01-23 at 11.26.30 AM.png
struct Person {
let firstName: String
let lastName: String
func getFullName(firstName: String, lastName: String) -> [Person]
}
return getFullName
2 Answers
Steve Hunter
57,712 PointsHi Matt,
There's a couple of ways of doing this. Here's my attempt:
struct Person {
let firstName: String
let lastName: String
func getFullName() -> String {
return "\(firstName) \(lastName)"
}
}
The function needs to be inside the struct and return the full name; a string. I used interpolation; you could concatenate, if you want.
Does that make sense?
Steve.
Matt Conway
1,572 PointsYeah, interpolation is better than concatenate. Didn't realize that return is supposed to be inside the function instead of outside. Still have some learning to do! Thanks for your help
Steve Hunter
57,712 PointsHey, no problem! And we all have a lot of learning to do - that's why we're here!
Good luck.
Steve.