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 trialNATHAN TRAN
2,367 PointsIs my struct and constant correct?
Where do the constants aPerson and myFullName go?
struct Person {
let firstName: String
let lastName: String
func fullName() -> String {
return "\(firstName) \(lastName)"
}
}
struct Person {
let aPerson = String
let myFullName = "\(firstName) \(lastName)"
print(aPerson(myFullName))
}
1 Answer
Christopher Jr Riley
35,874 PointsYour first struct is correct. However, the second struct isn't. As a matter of fact, it's not needed at all.
What the challenge is asking for is for you to assign the instance of Person to the constant that's named aPerson. It would look similar to this:
let aPerson = Person(firstName: "John", lastName: "Doe")
After that, it's asking you to call out the function that you just made (fullName()) and assign it to the constant called myFullName:
let myFullName = aPerson.fullName()
For reference, here's the full code:
struct Person {
let firstName: String
let lastName: String
func fullName() -> String {
return "\(firstName) \(lastName)"
}
}
let aPerson = Person(firstName: "John", lastName: "Doe")
let myFullName = aPerson.fullName()
Hope this helps.
NATHAN TRAN
2,367 Pointsthis is the full code?:
struct Person { let firstName: String let lastName: String
func fullName() -> String {
return "\(firstName) \(lastName)"
}
let aPerson = Person(firstName: "Nick", lastName: "Young")
let myFullName = aPerson.fullName()
}
Christopher Jr Riley
35,874 PointsChristopher Jr Riley
35,874 PointsYes, the code you posted below should be correct.