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 trialMaxence Roy
8,753 PointsI'm a bit stuck here. I'm trying to return the "full name", can someone give me a tip ?
Task: Given the struct below in the editor, we want to add a method that returns the person’s full name. Declare a method named fullName() that returns a string containing the person’s full name. Note: Make sure to allow for a space between the first and last name.
struct Person {
let firstName: String
let lastName: String
func fullName(firstName: String, lastName: String) -> fullNameWithSpace {
let firstName = "Jenny"
let lastName = "Tremblay"
let fullNameWithSpace = firstName + " " + lastName
}
}
2 Answers
Alexander Davison
65,469 Pointsstruct Person {
let firstName: String
let lastName: String
func fullName() -> String {
return firstName + " " + lastName
}
}
First, you didn't return a value from your function. Second, the challenge didn't ask you to be able to take in parameters. Third, Your return type is invalid. fullNameWithSpace
is a variable name, not a type like String
or Int
or Double
. Lastly, you have a fixed value for the variables firstName
and lastName
. The challenge didn't ask you to have the variable be a fixed value.
The solution code is shown above.
I hope this helps.
~Alex
Maxence Roy
8,753 PointsThanks a lot Alex ! I'm gonna need to work a bit more at this.
Alexander Davison
65,469 PointsNo problem!
By the way, can you please provide a Best answer? It will mark your question as answered in the forum (community). Thank you very much! ~Alex