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 trialDavid Galindo
Courses Plus Student 2,294 PointsFunction Return Types
For this challenge we are ask to modify the current function with a return type and yo use the println, the output should say "Hello Tom". the part that I am having trouble is when call the function in the println. I thought that the println statement should look like this.
println("Hello (greeting("Tom"))") but this does not compile why is that ??
4 Answers
Andres Oliva
7,810 PointsI don't believe that you can use string interpolation that way.
You can use something like this:
println("Hello" + greeting("Tom"))
or this:
let greeting = greeting("Tom")
println("Hello \(greeting)")
but that line of code you're writing doesn't make much sense to me.
David Galindo
Courses Plus Student 2,294 PointsIt doesn't really help me, but thank you
David Galindo
Courses Plus Student 2,294 Pointswhy is this wrong ???
func greeting (person : String) ->String{
return person
}
println("Hello \(greeting ("Tom"))")
David Lu
17,493 PointsWhat Andrew says...
And also, Swift (or many other languages) don't like double quotation marks inside a double quotation marks.
David Galindo
Courses Plus Student 2,294 PointsThank you I figured it out !!!!
David Lu
17,493 PointsDavid Lu
17,493 PointsYou can find a similar question posted in this forum
https://teamtreehouse.com/forum/using-the-return-type