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 trial
Greg Josephs
1,350 PointsHello, I am stuck on the second step of the decomposing tuples challenge. I know my code is correct but I can't advance
Here's the code. What am I missing? It works perfectly in Xcode
func greeting (#person: String, #language: String) -> (language: String,greeting: String) { let language = "English" let greeting = "Hello (person)"
var languageGreeting = (language, greeting)
return languageGreeting
}
var result = greeting(person: "Tom", language: "English")
2 Answers
Jeremy Hayden
1,740 PointsGreg,
You forgot to name the tuples in your return statement.
return (greeting:greeting, language:language)
func greeting(person: String) -> (greeting:String ,language:String){
let language = "English"
let greeting = "Hello \(person)"
return (greeting: greeting, language: language)
}
You will find the code challenges expect exact answers. I have seen it mark an answer wrong because a word was not capitolized. Good luck on the rest of your courses!
Greg Josephs
1,350 PointsThanks,
It seems that while working in Xcode I added the extra step of creating a tuple called languageGreeting within the function and simply returning that variable. Your solution definitely cut out the extra step and gave the challenge exactly what it was looking for. Thanks for alleviating my frustration!
Daniel Templin
5,293 PointsStrange, I didn't name mine when I was testing for my response and it didn't have a problem. It is very picky though, so naming them probably would not have hurt. :)
Daniel Templin
5,293 PointsI think there are a couple of problems with what you have there (though the code itself would be functional I think).
Your return value appears to need to be formatted as (greeting: String, language: String), and not the other way around. It's not that it will not return those two values, I think the problem lies in the quiz system checking it and seeing the "wrong" return value being used first.
Also, you should only need a single parameter. It may work with two, but since it's picky enough to dislike return values being in the wrong order, you will almost definitely run into issues with it. The default parameter they have (person: String) works for the entire assignment. You could definitely add the # sign for a named parameter, but that would be the only modification you would really need.
Soojin Ro
13,331 PointsSoojin Ro
13,331 PointsWhat was the mission? maybe you understood it wrong