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

Alex Nwarueze
Alex Nwarueze
2,172 Points

why isn't this code working?

func greeting(person: String) -> String { return person } println("Hello (greeting("Tom"))")

returns.swift
func greeting(person: String) -> String{
    return "Hello" && person
}
//println("Hello \(greeting("Tom"))")

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

The && 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
Alex Nwarueze
2,172 Points

Thanks Jennifer, appreciate the help.