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
Frankie Levangie
1,808 PointsIn Stage 2 Tuple task 2 of 3. Create a variable named result and assign it the tuple returned from function greeting.
I'm confused with assigning a tuple to the variable named result from function greeting. Can't seem to figure it out. Any help will do. Thanks
//Treehouse code func greeting(person: String) -> String { let language = "English" let greeting = "Hello (person)"
return greeting
}
//My attempt func greeting(person: String) -> (language: String, greeting: String) { let language = "English" let greeting = "Hello (person)" var result = (language, greeting) return (greeting, language) } greeting("Tom")
9 Answers
Frankie Levangie
1,808 Pointsvar result = greeting("Tom")
kaitlanlang
3,042 PointsWell I'm puzzled, if you paste exactly what you have into Xcode playground it works perfectly as you have presented it. Give me 10 minutes for a coffee and i will take a close look. I think if it works in Xcode but is not parsing when you submit it it maybe something really pepantic such as a string typo for example. Back soon :)
Mackenzie Moynihan
1,499 PointsThanks so much!
kaitlanlang
3,042 PointsTo much is assumed a known here, it is abvious when you show this answer but until you see it its not clear in a newly learning head what is being asked. Questions need to be really consise. I thought question was asking me to asign that within the code along the lines of 'var result = return (greeting, language)' which is way wrong. I would have arrived at the above answer if I felt it clear what was being asked. Knowledge to this point hasnt been to hard its understanding the task requested.
Mackenzie Moynihan
1,499 Pointsfunc greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
var result = greeting("Tom")
return (language, greeting)
}
I've tried every way I could think of to fix the code but every time its says the result is not assigned to the greeting function. This is stage 2 challenge 2 of 3
kaitlanlang
3,042 PointsAssign it the tuple 'returned from' is the operative word. So for want of a better explanation the tuple is being returned outside that block of code, so to access or create a variable using what was returned needs to be outside block off code. Try doing exactly what you have done but put the variable completely outside block of code.
Mackenzie Moynihan
1,499 Pointsfunc greeting(person: String) -> (language: String,greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
var result = greeting("Tom")
Mackenzie Moynihan
1,499 Pointsthe error says that I have the wrong value assigned to the var result.
kaitlanlang
3,042 PointsCan't figure out why it isn't parsing. Knowing it works in Xcode and Knowing that the answer is var result = greeting ("Tom") I suggest you refresh the web page and enter answer at bottom, I can only guess you have some whitespace maybe??? thats treated as a value by the parser. It can be so pedantic, I have reversed 2 letters in text in a println statement and wouldn't work which of course will in Xcode. Good luck sorry I couldn't help.
(btw the reason greeting("Tom") is outside code block is "Tom" is being delivered to 'person:string' at start of function. I am sure it could be described better than i have but I'm a newbie at this)
Mackenzie Moynihan
1,499 PointsThank you for trying! I've been stuck on this all day! I will try and look at the spacing and maybe I can get it correct. I found that I put it in the wrong order and when I switched to return I got it correct.
Byron Thompson
729 Pointsfunc greeting(person: String) -> (language: String, greeting: String) { let language = "English" let greeting = "Hello (person)" return (greeting, language) // for some reason it will only accept the code when you swap these around } var result = greeting ("Tom")
Igors Devels
1,272 Points// Problem was in order of "greeting" and "language". Order should be the same.
func greeting(person: String) -> (greeting: String, language: String) { let language = "English" let greeting = "Hello (person)"
return (greeting, language)
}
var result = greeting("Tom")