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 trial

iOS Swift Functions and Optionals Functions Syntax and Parameters

function person string

Modify the println statement within the greeting function to use the variable person. For example, if you pass a person named "Tom" to the function then it should display: Hello Tom. (Hint: you must use string interpolation).

I am lost here...

8 Answers

Logan R
Logan R
22,989 Points

It just wants you to run the function below your code given the input, Tom.


func apple(size,color) {
    println("The apple is " + size + " and is " + color + ".")

apple(giant,red) // This will produce "The apple is giant and is red."

I am having a difficult time with this challenge. I am getting this error message: Bummer! Your greeting printed "HelloTom." when called with "XYZZY" as the parameter. It should have printed "Hello XYZZY".

My code is: func greeting(person: String) { println("Hello" + person + ".") } greeting("Tom")

Logan R
Logan R
22,989 Points

You need to add a space after hello.

"Hello" + person


"Hello " + person


Thank you for the response. I was able to decipher after reading the question once again. It did not really ask for me to run the code, using person ( Tom ) and I kept on including it ( For example, if you pass a person named "Tom" to the function then it should display: Hello Tom.) So, once I left it out, it went thru. They were simply asking the format, and I kept on trying to call it.

Thank you.

Logan R
Logan R
22,989 Points

Glad you got it figured out :)

Eric Freeburg
Eric Freeburg
1,368 Points

Getting rather frustrated. I tried the aboves, and the following below. Any help would be great Thanks.

func greeting(person: String) {
    println("Hello \(person)")
Akilah Jones
Akilah Jones
18,397 Points

String interpolation involves using the variable(s) inside of a string, which is different than string concatenation which can include multiple sub-strings

let name = "Akilah"

//String concatenation
println("My name is " + name + " and I like to sing")  

//String interpolation
println("My name is \(name) and I like to sing.") 

//Both println statements print "My name is Akilah and I like to sing" to the console

You pass values to functions by placing a variable name inside the parenthesis of the function definition

//function definition
func passVariable(variable_name) {
   println(variable_name)  //prints some value to the console

//function call
passVariable("Akilah")  // prints "Akilah" to the console

Hope that helps

Best Regards


@ Logan and co.

I am still getting this message. "Your greeting printed "Hello Tom." when called with "XYZZY" as the parameter. It should have printed "Hello XYZZY".

It looks like I got it right, and followed your advise on adding a space after hello, then why is it still giving me the error message ?

louis currie
louis currie
11,213 Points

Don't call the function and it will work.

This is the solution :

func greeting(person:String) { let person = "XYZZY" println("Hello (person)")

} greeting("XYZZY")

Answer is

func greeting(person:String) { print("Hello (person)") }