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 trialAndrey Kondratyuk
Courses Plus Student 1,723 PointsCannot assign proper value to var result
I get an error that says "Bummer! You need to assign the return value from greeting() to result"
I don't see what's wrong with this code. Can someone please advise?
func greeting(person: String) -> (language : String, greeting : String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
var result = greeting(person : "Tom")
3 Answers
Chris Shaw
26,676 PointsHi Andrey,
This is neither a bug in Swift or in the code challenge but something that's very easy to misunderstand when it comes to parameters and tuples.
- You only need to declare the parameter name in the function call if it's defined using an hash/pound
- In the case of this challenge the tuple does indeed need to be in order as per the question.
However, point 2 and tuples have some other abilities which you've learned about except for one which is you can set tuples out of order except for when you're setting them in the return type.
To see what I mean by this visit the below link.
Hope that helps.
Andrey Kondratyuk
Courses Plus Student 1,723 PointsGoogling around a bit it looks like this might be a bug?
Is the order of language and greeting important? It seems like as long as they are declared and returned in the same order that should be fine?
Can I not include person: when I run the function?
I got this working like this:
func greeting(person: String) -> (greeting : String, language : String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
Melissa Garza
12,671 PointsThank you so much, this fixed it for me :) I had the last line correct and since the previous code passed the previous challenge, I was so confused as to what could be causing the error.
I had followed the order that the language and greeting constants were given in the provided code (language, greeting) instead of how the question asked for it (greeting, language).
I believe the order is important, it's just that the first challenge didn't check for that.
David Galindo
Courses Plus Student 2,294 Pointshello Andrey in the case for treehouse they are a bit picky in the order of of greeting and language. I had the same trouble when I completed the challenge. What I like to do is I open up the playground in Xcode and work on it there and play with it to see if order matters, do I get the same result? and other stuff. I have that some of the challenges are picky in the order that want us to write the code but it's a good habit to do this way.
Andrey Kondratyuk
Courses Plus Student 1,723 PointsGreat advice. I will do that.
Andrey Kondratyuk
Courses Plus Student 1,723 PointsAndrey Kondratyuk
Courses Plus Student 1,723 PointsThank you. That definitely helps.