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 trialMatthew Sharikov
5,767 PointsMethods - Swift 3
Can someone please help me with this problem?
methoed fullName() String: Matthew Sharikov
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Matthew! I would like to first suggest that you review the appropriate videos regarding methods (the two videos preceding this challenge).
But here's some general information about methods. A method is a type of function. All methods are functions, but not all functions are methods. The difference between a method and a function is that methods are defined inside a class or struct.
Here you've tried to write "method", but misspelled that. But even so, it should be func
. The code inside the method belongs inside a set of curly braces as it will be the block of code executed when the method is called. Also, the method should return a string. It looks almost like you're trying to define a string, but even then your name is missing any quotes to make a string literal. Remember, the firstName and lastName variables are already set up for you. You should be using these to generate the string returned by fullName
.
//using interpolation
func fullName() -> String {
return "\(firstName) \(lastName)"
}
//using concatenation
func fullName() -> String {
return firstName + " " + lastName
}
Either one of these are valid solutions, but they use different methods to put together the final string. In each case, we start by defining a func
named fullName
as per the challenge requests. We then say what data type we'll be returning (in this case a String). Next, we include our code block which returns the full name of the person which is created from the combination of the firstName
together with the lastName
.
Hope this helps!
Matthew Sharikov
5,767 PointsThank you Jennifer! I added extra curly braces with the concatenation method at the end and it worked.