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 trialAlex Nwarueze
2,172 Pointswhy isn't this code working?
func greeting(person: String) -> String { return person } println("Hello (greeting("Tom"))")
func greeting(person: String) -> String{
return "Hello" && person
}
//println("Hello \(greeting("Tom"))")
1 Answer
Jennifer Nordell
Treehouse TeacherThe && operator is used in comparisons. For example x is less than y AND x is greater than 0. If y was 10 and x was 2 then that would evaluate to true.
What you're looking for here is either concatenation or interpolation. In their code they already give you the interpolated version of the string. Here's what the final answer looks like:
func greeting(person: String) -> String {
return "Hello \(person)"
}
Interpolation uses the backslash and parentheses to tell the compiler to put the value stored in that variable in that spot. If you had written return "Hello person" then it would literally return "Hello person" instead of "Hello Alex" or whatever name you had passed in. Hope that clarifies things!
Alex Nwarueze
2,172 PointsAlex Nwarueze
2,172 PointsThanks Jennifer, appreciate the help.