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 trialJack Ames
501 PointsThis says I have it wrong but I was positive I got it right!
What should i do
func greeting(person: String) {
println("Hello \(person)")
}
greeting("Tom")
2 Answers
Martin Wildfeuer
Courses Plus Student 11,071 PointsCurrently our greeting function only returns a single value. Modify it to return both the greeting and the language as a tuple. Make sure to name each item in the tuple: greeting and language. We will print them out in the next task.
This assignment is all about returning values from functions. To be more specific: Tuples, that is more than a single value.
The way you changed the code, greeting
does not return anything anymore, but prints to the console.
So how does the return type tuple look like? Well, not unlike what we pass to the function if we have multiple values. If we wanted to return two strings, the function would look like this
func aFunction(aString: String) -> (firstString: String, secondString: String) {
. . .
}
So, how would the return statement inside the function body look like?
func aFunction(aString: String) -> (firstString: String, secondString: String) {
let stringOne = "I am the first String"
let stringTwo = "and I am the second!"
return (stringOne, stringTwo)
}
Although we are not using aString
for this example, we are returning two string values as soon as the function is called.
Let's try and apply this to the assignment!
Oliver Burnand
935 PointsThanks a lot!