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 trialJames Pask
Courses Plus Student 839 PointsPlease Help
I need to create a fucntion named greeting and give it a parameter called "person" so basically the output is the name in the string plus "hello"
func greeting(person: str) {
let greeting + string
println("Hello") + string
}
3 Answers
Logan R
22,989 PointsYou have a couple things wrong.
func greeting(person: String) {
// Command
}
When you make a variable a defined object, you use the colon. Here, they are asking for a string, so you need to define it as a string using "String".
Second:
When you concatenate (Add one to another) a string, you need to put the concatenation inside of the println.
println("Can you see " + person + " okay?")
I hope this helps you out some!
shaunbaker04
1,719 PointsHere is the answer to that question:
func greeting(person: String) { println("Hello (person)") }
But don't just copy and paste it and click next. Understand what it is doing and what is going on here or you have gained nothing and will need further advice in the future. ;-)
Cesar De La Vega
13,900 PointsThis worked for me
func greeting(person: String) { println("Hello (person)") }
James Pask
Courses Plus Student 839 PointsJames Pask
Courses Plus Student 839 PointsThankyou once again Logan for saving me aha
James Pask
Courses Plus Student 839 PointsJames Pask
Courses Plus Student 839 PointsWhat now? I need to put the name Tom in place where "person" is. I always get confused with where you put the data bit like this.
```func greeting(person: String) { println("Hello" + person) }
Logan R
22,989 PointsLogan R
22,989 PointsIt just wants you to run the function below your code given the input, Tom.
Example:
James Pask
Courses Plus Student 839 PointsJames Pask
Courses Plus Student 839 PointsTried that and it failed saying this "Your
greeting
printed "HelloTom" when called with "XYZZY" as the parameter. It should have printed "Hello XYZZY"."This was the code
And when i didnt put speech marks on Tom it just said "could not compile"
Logan R
22,989 PointsLogan R
22,989 PointsYou need a space after hello
println("Hello " + person)
The thing is very particular like that :P
James Pask
Courses Plus Student 839 PointsJames Pask
Courses Plus Student 839 PointsThis is the instructions.. what am i missing? I think its the string iterpolation?
"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)."
Code
Logan R
22,989 PointsLogan R
22,989 PointsYou added the greeting("Tom") too soon. Remove it then click "next" then add it back for task 3, lol.
James Pask
Courses Plus Student 839 PointsJames Pask
Courses Plus Student 839 Pointsyeah that worked haha. So annoying that was the problem. They should tell you but then i guess if i understood it would probably have been clear. Anyway thanks for the help :)