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

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,857 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