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 trialAnders Lund
3,061 PointsReturn Statement wrong?
Don't know whats wrong here, i'm trying to return a string from the func. "greeting" but there is something wrong, plz help :)
func greeting(person: String) {
return "Hello "+ person
}
greeting ("Tom")
3 Answers
Ryan Jin
15,337 PointsYou have to specify the return type in the function by using a -> and the return type, so your code should look something like this:
func greeting(person: String) -> String{
return "Hello "+ person
}
greeting ("Tom")
If you are not returning anything, or in another word, you are returning void, you can either ignore the -> (type) or write -> Void, but if you are returning a type like an int or a string, you have a specify it. Hope that helps you :)
Anders Lund
3,061 Pointsaha, thank u :)
Anders Lund
3,061 PointsU also have to change this //return "Hello "+ person to //return "Hello (person)" for it to run, atleast in the teamThreeHouse program thing.
Ryan Jin
15,337 PointsYeh, probably programmed too much Javascript and I forgot this, thanks for reminding me