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 trialEmmancipate Musemwa
1,311 PointsFunctions and Operations, Code cannot compile
I am trying to use to the function to return a string func greeting(person: String) -> String { return person
}
println("Hello (greeting("Tom"))")
func greeting(person: String) -> String {
return person
}
println("Hello \(greeting("Tom"))")
1 Answer
Chris Shaw
26,676 PointsThe code you have is vastly different from what the challenge has asked for, just for clarity the question is as follows.
Modify the definition of the function named
greeting
to return aString
and replace the println statement with a return statement. The function should return a greeting. For example, if you pass in a string "Tom" then the return string would be: "Hello Tom".
What the challenge is asking us to do is alter the function so instead of using the println
function to print the string we simply return it, to do this we simply need to replace println
along with it's parentheses which will give you the return
statement containing the same string that the println
function was printing.
See the below.
func greeting(person: String) -> String {
return "Hello \(person)"
}
Happy coding!
Emmancipate Musemwa
1,311 PointsEmmancipate Musemwa
1,311 PointsThanks a lot now I clearly understand it