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 trialpatrtoikua
1,871 PointsCan you guys help me with this Return Type Function.
Thanks for help.
//This code works:
func fullName(firstName: String, lastName: String) -> String {
return firstName + lastName
}
let name = fullName("Jose Paulo ","Garcia")
println("Hello \(name)")
// or
fullName("Jose Paulo ","Garcia")
// This code does not work:
func fullName(firstName: String, lastName: String) -> String {
return firstName + lastName
}
println("Hello \(fullName("Jose Paulo ", "Garcia"))") //<----- expected separator
3 Answers
Stone Preston
42,016 Pointsthe multiple quotations are probably what are causing the problem. the compiler sees the first double quote in front of hello, then gets to the second double quote inside the function call and thinks thats one string.
you can try to use one type (single or double) for the outer quotes, and the other for the inner quotes:
println("Hello \(fullName('Jose Paulo ', 'Garcia'))")
I used double quotes for the outer quotations of the println string, and single quotes for the string parameters.
im not certain that will work though, as swift might require string to be enclosed in double quotes.
Chris Hedstrom
3,024 PointsThanks, I had exactly the same question and was setting it up the same way.
Anubhav Chopra
1,094 PointsIf you don't want to print the "Hello" you can -
func fullName(firstName: String, lastName: String) -> String {
return firstName + lastName
}
println(fullName("Roger","Barry"))
patrtoikua
1,871 Pointspatrtoikua
1,871 PointsI tried that one too but it didn't work. Thank you though.
Stephen Whitfield
16,771 PointsStephen Whitfield
16,771 PointsYour comment regarding strings needing to be enclosed with double quotes is correct. The only way around this that I've found is setting the function to some object or using string concatenation.
patrtoikua
1,871 Pointspatrtoikua
1,871 PointsAwesome it did work! Thanks a lot guys! Appreciate. Now I can finally sleep well tonight.