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

I'm stuck with this challenge. Who can help? By the way I ran this code through Swift and it worked. A little confused

heres the code

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,631 Points

Hey Alex.

I think you may have got a tad confused by the task in question. You are asked to modify the definition of the function so that it returns a string. This is done with the -> symbol after the parameter declaration. Then it asks to return the string, It gives an example with the value of "Tom" was passed in. BUt, it doesn't want you to hard-code the value in, it is just giving an example. You will see that challenges are very specific and very picky. Also, you are printing the string out, when the challenge asks for a return.

Below is the correct lines of code for your reference. I hope it will make sense. :)

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

:dizzy:

Alex Nwarueze
Alex Nwarueze
2,172 Points

Makes absolute sense. Thanks Jason