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 trialTim Watkins
16,034 Pointsswift 3.0 Method Instince
Need some help not sure what I'm Missing or doing wrong
Challenge Task 1 of 2
Given the struct below in the editor, we want to add a method that returns the personโs full name. Declare a method named fullName() that returns a string containing the personโs full name. Note: Make sure to allow for a space between the first and last name Bummer! Make sure you're adding an instance method named fullName() to the struct definition Restart Get Help Recheck work structs.swift
1 struct Person { 2 let firstName: String 3 let lastName: String 4 func fullName( Name firstName: String, Last lastName: String) -> String [Person] { 5 return fullName(Name: " ", Last: " ") 6
7 } 8 }
struct Person {
let firstName: String
let lastName: String
func fullName( Name firstName: String, Last lastName: String) -> String [Person] {
return fullName(Name: " ", Last: " ")
}
}
3 Answers
kjvswift93
13,515 PointsYou don't need to add any parameters to the fullName function. All the function needs to know is that it will be returning a string.
struct Person {
let firstName: String
let lastName: String
// Challenge 1
func fullName() -> String{
return "\(firstName) \(lastName)"
}
}
// Challenge 2
let aPerson = Person(firstName: "Jane", lastName: "Doe");
let fullName = aPerson.fullName()
Tim Watkins
16,034 PointsAwesome Thanks. Yeah was adding to much that wasent needed. Thanks
Tim Watkins
16,034 PointsThe second challenge not passing not sure whats wrong?
Conor Mosier
3,866 PointsConor Mosier
3,866 Pointsliterally copied and pasted this code and it doesn't work.