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 trialAdam Little
6,735 PointsiOS Development with Swift - Tuples - Challenge 2 / 3?
"Create a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to the greeting function.)"
I think I'm doing everything right, but I'm getting the following error message:
"Bummer! Your result
variable has the wrong value in it. Check the task instructions again."
Can someone please lend me another set of eyes and let me know what I'm doing wrong?
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language:language, greeting:greeting)
}
var result = greeting("Tom")
4 Answers
William Davis
5,497 PointsHey, Adam,
The code you're looking for is:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
You only have to specify once what you want to return inside the return function :)
Anthony Price
1,412 PointsWilliam -
I have used exactly this and it works in Xcode. However, task 2 does not like the result. Please, help?
William Davis
5,497 PointsHey, Anthony.
It does work for me. Make sure you haven't misspelled anything ;)
I'll write here what I use to achieving the challenge:
Task 1:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
Task 2:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
Task 3:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
println(result.language)
Good luck :)
Anthony Price
1,412 PointsWilliam - Thanks for the quick response! Here is what I am using:
func greeting(person: String) -> (greeting: String, language: String) {
let language = " English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
Haven't been able to get to task 3.
William Davis
5,497 PointsFound it!
let language= "English"
You've got a space between " and English :D
Anthony Price
1,412 PointsGood lord! I'm going blind! Thanks for the help!!!!
William Davis
5,497 PointsYou're welcome! And don't worry: it happens to all of us ;)
Adam Little
6,735 PointsAdam Little
6,735 PointsThank you very much!