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 trialYao Liu
1,733 PointsWhat is wrong this time
This was my previous thread https://teamtreehouse.com/community/why-does-this-code-return-that-i-didnt-add-an-instance-method Now, it returns this, even though it clearly does exist.
Bummer! Make sure you're adding an instance method named getFullName() to the struct definition
struct Person {
let firstName: String
let lastName: String
func getFullName () -> String{
return "\(firstName) \(lastName)";
}
}
let aPerson = Person(firstName : "Yao", lastName : "Liu");
let fullName = aPerson.getFullName;
3 Answers
Jennifer Nordell
Treehouse TeacherHi there! This time it's just a couple of tiny errors. You have an extra space between the name of the function and the parentheses that is causing the challenge to fail. Also on step 2 you will need parentheses to call the method on the instance of the Person object. So you will need:
let fullName = aPerson.getFullName();
And change this:
func getFullName () -> String{
To this:
func getFullName() -> String{
Hope this helps!
Alexander Davison
65,469 PointsYou forgot parentheses after aPerson.getFullName
:)
Try this instead:
struct Person {
let firstName: String
let lastName: String
func getFullName () -> String{
return "\(firstName) \(lastName)";
}
}
let aPerson = Person(firstName : "Yao", lastName : "Liu");
# Over here, I added () after aPerson.getFullname
let fullName = aPerson.getFullName();
Good luck! ~alex
EDIT: Like what Jennifer Nordell said, you must also get rid of the extra space before () -> String
Aananya Vyas
20,157 Pointsstruct Person {
let firstName: String
let lastName: String
//here we need a function called fullName() explicitly acc to the code challenge
///returns full name
func fullName() -> String{
return "\(firstName) \(lastName)"
}
}
let aPerson = Person(firstName : "anan", lastName : "vy")
//the constant can be named anything coz it is unspecified
let getfullName = aPerson.fullName()```
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsNice one! Didn't know you can't have a space before the parentheses :)
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherI think you actually can in Swift, but it does cause it to fail in step 1 of the challenge. I'm not on my Mac right this second so I can't confirm
Yao Liu
1,733 PointsYao Liu
1,733 Pointsthanks. its those little things that people spend hours looking for in bugged code. ¬_¬