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 trialBob Clanfield
2,372 PointsNo idea what I'm doing wrong or right.......
I've restarted this track 5 times over and feel zero momentum. I feel like I've accomplished all requests of the challenge and Xcode compiles it. When I start refactoring, I find myself looking down the rabbit hole.
struct Person {
let firstName: String
let lastName: String
func fullName() -> String {
let fullName = "\(firstName) \(lastName)"
return fullName
}}
let aPerson = Person(firstName: "Hunter", lastName: "Thomson")
let myFullName = aPerson
myFullName.fullName()
1 Answer
Matthew Long
28,407 PointsYou're doing great! You're really close. Looks like you need to move the fullName()
method up a line. Might be an issue with the challenge. There's no error in the preview or in Xcode. You can also clean up your indentation a bit:
struct Person {
let firstName: String
let lastName: String
func fullName() -> String {
let fullName = "\(firstName) \(lastName)"
return fullName
}
}
let aPerson = Person(firstName: "Hunter", lastName: "Thomson")
let myFullName = aPerson.fullName()
One last thing to note. You don't have to create a constant fullName
and then return it. You can return the string in one line:
struct Person {
let firstName: String
let lastName: String
func fullName() -> String {
return "\(firstName) \(lastName)"
}
}
let aPerson = Person(firstName: "Hunter", lastName: "Thomson")
let myFullName = aPerson.fullName()