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 trialMazen Wasel
1,153 PointsMy code's correct but its not being accepted. It works in Xcode. Maybe I have the right solution for the wrong question?
Bummer! The value being assigned to fullName must be a result of calling the instance method getFullName()
struct Person {
let firstName: String
let lastName: String
func getFullName() -> (String){
let fullName = "\(firstName) \(lastName)"
return (fullName)
}
}
let aPerson = Person(firstName: "Mazen", lastName: "Wasel")
let fullName = aPerson.getFullName()
2 Answers
Brian Steele
23,060 Pointsstruct Person {
let firstName: String
let lastName: String
func getFullName() -> String {
return "\(firstName) \(lastName)"
}
}
let aPerson = Person(firstName: "Mazen", lastName: "Wasel")
let fullName = aPerson.getFullName()
Your code does compile in XCode, but some of the challenges are a little picky about the exact approach. This should get you passing.
Mazen Wasel
1,153 PointsThank you Brian.
It seems that the problem was the brackets around String...
it did not accept the following: func getFullName() -> (String) {
but it accepted the following: func getFullName() -> String {
Does anyone know if the brackets are correct or incorrect syntax? or are they necessary at all or only in some cases?
Brian Steele
23,060 PointsNot necessary unless you are returning a tuple
Mazen Wasel
1,153 PointsMakes sense, Thanks!
Kyle Lambert
1,969 PointsKyle Lambert
1,969 PointsHi Mazel, you're code looks good and it runs in my complier. Try refreshing your browser. Also to make it easier to write, inside the method, their is no need to declare a constant named
fullName
you can achieve the same result with just codingreturn "\(firstName) \(lastName)"
Should look like this, but either way is correct.