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 trialKishan Solomon
1,135 PointsSecond objective for Tuples challenge
I don't know what I'm doing wrong here.
The question is:
"Create a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to the greeting function.)"
Here's my code:
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
var result = greeting("Tom")
And here's my error:
"Bummer! Your result
variable has the wrong value in it. Check the task instructions again."
I mean, it's a bit weird because greeting is the function and a constant in the function. But the code works fine on my Xcode and it returns the tuple.
I can even return the constant greeting with result.greeting. What am I missing?
3 Answers
Meek D
3,457 Pointsyou are on the right track , They ask you to return (greeting and language ) not language then greeting .
func greeting(person: String) -> (greeting : String,language : String ){
let language = "English"
let greeting = "Hello \(person)"
return (greeting ,language)
}
var result = greeting("Tom")
Kirk Burgess
1,129 PointsI'm not sure how one comes to this conclusion. How is one to know in the 2nd stage of the challenge that greeting & language in the return tuple are listed the wrong way around?
Kishan Solomon
1,135 PointsOh, you are right. I switched it just so it matched the order they gave it in the function. I forgot they would expect the original order for the Tuple.
Thanks a lot!
Meek D
3,457 PointsI am glad to Help you :)
Nathan Fincher
1,038 PointsThis is the first time I've been ill with Treehouse. I had the same problem. What gets me ill is task 1 allowed me to use the tuple backwards when I couldn't in task 2. So I assumed I could use the same code as in task 1. I'm also ill that they named the function the same name as one of the constants in the function. Is that common or is there a reason for this? I just spent an hour trying to get it on my own to realize the code from task 1 accepted an incorrect answer. (They wanted greeting then language but it accepted it as language then greeting)
Nathan Fincher
1,038 PointsGot it easily after that. Thank you for clarifying the problem, Meek D. I could have been here another 2 hours not realizing I had the tuple backwards.
Casey Woelfle
Courses Plus Student 1,861 PointsCasey Woelfle
Courses Plus Student 1,861 PointsI think this might be a bug with the challenge. Maybe you should contact support on this one.