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 trialNicholas Kennedy
14,015 PointsWrong Answer? Compiles fine in xCode
//Bummer! Make sure you're assigning the results of calling the getFullName() method to a constant named aPerson
Did I miss something or is this the treehouse compiler being fickle?
//Bummer! Make sure you're assigning the results of calling the getFullName() method to a constant named aPerson
struct Person {
let firstName: String
let lastName: String
func getFullName() -> String {
let fullname = firstName + " " + lastName
return fullname
}
}
let aPerson = Person(firstName: "Nick", lastName: "Me")
aPerson.getFullName()
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Nicholas,
Mostly it's the code checker just being finicky.
I'm actually surprised the checker allowed your Task one to pass. While your code is syntactically correct, it wasn't what the checker wanted for Task one.
The challenge doesn't want you to assign the fullName
constant inside of the function. Instead that should just return the full name. return firstName + " " + lastName
.
The constant fullName
gets declared as part of the function call at the end.
What you need for this challenge is this:
struct Person {
let firstName: String
let lastName: String
func getFullName() -> String {
return firstName + " " + lastName
}
}
let aPerson = Person(firstName: "Nick", lastName: "Me")
let fullName = aPerson.getFullName()
Hope that helps