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 trialKevin Walker
2,354 PointsHaving trouble returning strings
I am having trouble with the 1st part of the challenge on Structs. I have setup the function and have set the function for return types of two Strings with names firstName and lastName. Inside the body of the function, I have set the function to return those variables. The challenge is telling me to make sure my function has no parameters (which it does not) and that it is returning a String. I am assuming I am not supposed to do anything inside the function, even though the challenge asks for a complete full name. Here is where I currently am:
struct Person {
let firstname: String
let lastname: String
func getFullName() -> (firstname: String, lastname: String) {
return (firstname, lastname)
}
}
struct Person {
let firstName: String
let lastName: String
}
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Kevin,
You're kind of on the right track. First off, your return statement is a bit off. You can't include variables/constants in the return type... only the type.
Second, your return
statement is in the correct place, but you need to return a concatenated string that includes a space between the first name and last name.
Below is the correct code. Have a look, and I hope it makes sense. :)
struct Person {
let firstName: String
let lastName: String
func getFullName() -> String {
return (firstName + " " + lastName)
}
}
Keep Coding!
Kevin Walker
2,354 PointsKevin Walker
2,354 PointsThanks Jason! Another question: In previous videos, Pasan talks about setting up your return in the function declaration with names. Is that not appropriate here?
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsHi Kevin.
I watched the 2 videos prior to the quiz and was not able to find what you are referring to. In both videos, the return type of the function he has is a
Point
(or more specifically an Array of Points).If you could provide a link to the video you're referencing and a time-stamp, I'll have look. :)