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 trialLeonardo Cavalcanti
5,308 PointsSwift basics return type error
Q:Modify the definition of the function named greeting to return a String 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".
Not sure why this isn't the right answer... I can't compile the code either because it shows an error message.
func greeting(person: String)->String {
println("Hello \(person)")
return greeting("Tom")
}
Leonardo Cavalcanti
5,308 PointsDid that, also restarted my computer, tried using a different network... but im only stuck in this question the other ones work.
Dean Laurea
17,484 PointsDid you try copy and pasting my code? If you typed it manually there might be a syntax error. Also, have you tried using a different browser such as Chrome?
Leonardo Cavalcanti
5,308 Pointsright now im using safari, but I've used chrome too
Dean Laurea
17,484 PointsSorry, I don't know what the problem might be. Maybe your internet connection is affected? Might want to refresh the router.
2 Answers
Dean Laurea
17,484 PointsLeonardo,
Replace the print statement with a return statement and then call the function.
func greeting(person: String)->String {
return "Hello \(person)"
}
greeting("Tom")
Leonardo Cavalcanti
5,308 Pointsthis didn't work either, im still getting: Oh no! There was a communication problem.
If you continue experiencing problems, please contact support at help@teamtreehouse.com.
Leonardo Cavalcanti
5,308 PointsI've already contacted them but I've been told to post my code here.
Joshua Price
2,935 Pointsfunc greeting(person: String) -> String {
return ("Hello (person)")
}
// There needs to be a backslash before (person)
Leonardo Cavalcanti
5,308 Pointsmine has a backslash before (person)
Dean Laurea
17,484 PointsDean Laurea
17,484 PointsYou might need to refresh your browser.