Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Functions and Optionals Functions Function Return Types

Leonardo Cavalcanti
Leonardo Cavalcanti
5,308 Points

Swift 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.

returns.swift
func greeting(person: String)->String {
println("Hello \(person)")
return greeting("Tom")
}
Dean Laurea
Dean Laurea
17,484 Points

You might need to refresh your browser.

Leonardo Cavalcanti
Leonardo Cavalcanti
5,308 Points

Did that, also restarted my computer, tried using a different network... but im only stuck in this question the other ones work.

Dean Laurea
Dean Laurea
17,484 Points

Did 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
Leonardo Cavalcanti
5,308 Points

right now im using safari, but I've used chrome too

Dean Laurea
Dean Laurea
17,484 Points

Sorry, 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
Dean Laurea
17,484 Points

Leonardo,

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
Leonardo Cavalcanti
5,308 Points

this 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
Leonardo Cavalcanti
5,308 Points

I've already contacted them but I've been told to post my code here.

Joshua Price
Joshua Price
2,935 Points

func greeting(person: String) -> String {

return ("Hello (person)")

}

// There needs to be a backslash before (person)

Leonardo Cavalcanti
Leonardo Cavalcanti
5,308 Points

mine has a backslash before (person)