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 trialheather wolfram
1,594 PointsI cannot seem to figure out what I am doing wrong
how do I declare a method and get the right answer? no matter how I format it I cannot seem to get the correct answer.
struct Person {
let firstName: String
let lastName: String
}
func fullName() -> String {
let fullName = "\(firstName) \(lastName)"
return fullName
}
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Heather,
Everything you have there is correct. It's just the method needs to be inside of the struct instead of outside of it as it is now.
If you move the method inside, Task one will pass. Also, while syntactically correct, the challenge didn't ask for you to create a new variable. Your code does pass, but many times the challenges are very specific and highly picky... and if you just return the full name, the code is also much DRYer.
struct Person {
let firstName: String
let lastName: String
func fullName() -> String {
return "\(firstName) \(lastName)"
}
}
Keep Coding! :)