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 trialMark Angle
3,521 PointsHaving trouble with the method concept
Will someone please explain what I am doing wrong here? I am having trouble understanding why I cannot just return the simple constant fullName.
struct Person {
let firstName: String
let lastName: String
func getFullName() {
let fullName: String = "firstName" + " " + "lastName"
return fullName
}
}
1 Answer
Nathan Tallack
22,160 PointsSo, some shortcuts and some changes. Comments inline.
struct Person {
let firstName: String
let lastName: String
func getFullName() -> String { // Here we declare that we are returning a String
// No need to declare the fullName constant here if we are just using it for return
return "\(firstName) \(lastName)" // Returning an interpolated string.
}
}
Mark Angle
3,521 PointsMark Angle
3,521 PointsThank you. I was overthinking it as usual.