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 trialAditya Sanghi
8,044 Pointsfunc greeting(person: String) -> String { let language = "English" let greeting = "Hello \(person)" return greeting
Currently 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
func greeting(person: String) -> String {
let language = "English"
let greeting = "Hello \(person)"
return greeting
}
1 Answer
ankushdharkar
7,530 PointsHi Aditya. It seems that you have an incomplete question there. I presume you were unable to proceed with the challenge
The challenge is asking you to return a tuple of the two variables inside the definition of the function. To do so, you have to modify the return type in the function to the tuple to a type of (String, String)
, the same types as the two return values in the tuple (greeting
is a String
and language
is also a String
)
To make a tuple, you simply have to return a tuple of greeting
and language
variable like this: (greeting, language)
The full problem statement from viewing the challenge says: "Currently 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."
That means the return type needs to look like this: (greeting: String, language: String)
This program should pass the challenge:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
Let me know if you have further doubts. Good luck with Swift!
Anjali Pasupathy
28,883 PointsAnjali Pasupathy
28,883 PointsWhere are you having trouble? Is there an aspect of the question you don't understand? Did you write code that didn't pass? If so, could you state what aspect of the question you didn't understand, or post your code?