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 trialRoop P
Courses Plus Student 6,937 Pointsstructs.swift
//This Code is correct, but can't move forward. It happens sometimes as their (TTH's) site is looking for specific a process (or syntax). If anyone can tell me the specific way TTH wants this written- that will be nice! Thanks...
struct Person { let firstName: String let lastName: String
func fullName () -> String {
let fullName = "\(firstName) \(lastName)"
return fullName
}
}
let example = Person(firstName: "Annie", lastName:"Jones") example.fullName()
struct Person {
let firstName: String
let lastName: String
func fullName () -> String {
return "\(firstName) \(lastName)"
}
}
let example = Person(firstName: "Annie", lastName:"Jones")
example.fullName()
1 Answer
Matthew Long
28,407 PointsYour syntax is correct except it wants specific constants. Reread challenge two and it will tell you to create two constants. One named aPerson
and one named myFullName
:
struct Person {
let firstName: String
let lastName: String
func fullName() -> String {
return "\(firstName) \(lastName)"
}
}
let aPerson = Person(firstName: "Billy", lastName:"Boo")
let myFullName = aPerson.fullName()
Roop P
Courses Plus Student 6,937 PointsHey Matt, Thanks for reply! Unfortunately the challenge text does not include that. Here is what is reads
"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"
Though I will make the changes to move-forward. After applying that and moving the next part did mention as you wrote it. Thanks again
Matthew Long
28,407 PointsSorry. It appeared that you were already on challenge two because you were creating an instance of Person
and using the method you created in challenge one. That is the objective of challenge two:
Let's use the struct to create an instance of Person and assign it to a constant named aPerson. Assign any values you want to the first and last name properties. Once you have an instance, call the instance method and assign the full name to a constant named myFullName.
The reason you were having trouble with challenge one is the space between your function name and the parentheses. Remove that space and challenge passes
Roop P
Courses Plus Student 6,937 PointsAh! white space sensitivity with TTH. Thanks, I will keep an eye for that.
Roop P
Courses Plus Student 6,937 PointsRoop P
Courses Plus Student 6,937 Points//This Code is correct, but can't move forward. It happens sometimes as their (TTH's) site is looking for specific a process (or syntax). If anyone can tell me the specific way TTH wants this written- that will be nice! Thanks...