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 trialforrestsmith2
860 Pointsfunction 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
22,989 PointsIt just wants you to run the function below your code given the input, Tom.
Example:
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."
frederickparas
553 Points@Akilah,
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
22,989 PointsGlad you got it figured out :)
Eric Freeburg
1,368 PointsGetting 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
18,397 PointsString 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
AJ
frederickparas
553 Points@ 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
11,213 PointsDon't call the function and it will work.
thodang
983 PointsThis is the solution :
func greeting(person:String) { let person = "XYZZY" println("Hello (person)")
} greeting("XYZZY")
justin peralta
1,598 PointsAnswer is
func greeting(person:String) { print("Hello (person)") }
greeting("Tom")
frederickparas
553 Pointsfrederickparas
553 PointsI 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
22,989 PointsLogan R
22,989 PointsYou need to add a space after hello.
"Hello" + person
to
"Hello " + person