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 trialPeter Fuhrey
2,146 PointsConfusion about challenge task on functions return types in swift.
I'm new so sorry for anything that doesn't make sense but i'm generally just lost. I've tried everything I could think of can anybody help me?
func greeting(person: String) -> String {
let person = greeting(person)
return person
}
let person = greeting("Tom")
println("Hello \(greeting)")
1 Answer
kirkbyo
15,791 PointsHey Peter,
The question is asking you to return "Hello (Persons Name)". After creating the function is created, you declared an instance of person
instead of recalling the function you can just assign the following string (I called mine welcoming)
let welcoming = "Hello \(person)"
After that You can just simply return welcoming.
func greeting(person: String) -> String {
let welcoming = "Hello \(person)"
return welcoming
}
Think of the person
argument as a placeholder for whatever string that you pass to it. So when you declare the greeting function you just pass whatever name you would like.
func greeting(person: String) -> String {
let welcoming = "Hello \(person)"
return welcoming
}
greeting("Ozzie")
// return "Hello Ozzie"
greeting("Peter")
// return "Hello Peter"
I hope I answered your question. If you have another question don't hesitate to ask,
Ozzie