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 trialMia Pivirotto
5,557 PointsHow do you return a function that has a variable without using the println function to define the variable?
I'm trying to do the challenge for the function return and cannot figure out how to get my function to print out Hello Tom.
func greeting(person: String) -> String {
return "Hello greeting()"
}
1 Answer
agreatdaytocode
24,757 PointsHello Mia,
You almost have it.
func greeting(person: String) {
println("Hello \(person)")
}
greeting("Mia")
Try placing the above code in playground to see it in action!
Mia Pivirotto
5,557 PointsMia Pivirotto
5,557 PointsI'm still getting an error message. The point of the exercise is to take the println out of the code and replace it with return, but I must be getting the syntax wrong with the return. I have this:
func greeting(person: String) { return "Hello (person)" } greeting("Tom")
agreatdaytocode
24,757 Pointsagreatdaytocode
24,757 PointsMia, You don't need to add the greeting function it self.
only the following: