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 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.