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 trialRohan Prashanth
1,205 PointsCan someone help me figure out why my code for the code challenge isn't working?
The hint given is that I should make sure I am adding the instance in the struct definition
struct Person {
let firstName: String
let lastName: String
init(firstName: String lastName:: String) {
self.firstName = firstName
self.lastName = lastName
}
func fullName(firstName: String, lastName: String) -> Person {
var result = Person(firstName, lastName)
}
return result
}
1 Answer
Bruce Röttgers
18,211 PointsHey,
a struct doesn't need a custom initializer. Also the initializer definition has 2 errors:
- Between first name and last name parameters needs to be a comma.
- You used two colons behind the lastName parameter
the right way it would look like this
init(firstName: String, lastName: String) {
Next error, you are returning the result outside of the function.
Next error: The function should return a String and not an instance of Person
Next error: The string should be the first name + a space + the last name
Hope that helps, please don't forget to select this as a best answer if it solved your problem.
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsBrendan Whiting
Front End Web Development Techdegree Graduate 84,738 Pointscheck the preview tab, there's a lot of compiler errors