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 trialAlec Holmes
2,035 PointsError: "result variable has wrong value in it", even though it right
heres my code:
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
var greeting = (language, "Hello \(person)")
return greeting
}
let result = greeting("Tom")
i get a stupid error that says that the result variable has the wrong value in it even thought i am returning language and Tom.
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
var greeting = (language, "Hello \(person)")
return greeting
}
let result = greeting("Tom")
1 Answer
Stone Preston
42,016 Pointstask 1 states: Make sure to name each item in the tuple: greeting and language
Its not entirely clear but greeting needs to be the first element in the tuple and language second. change your return type and the return tuple around
// change the return type so that greeting is first, and language second
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
// make the greeting the first element, and language second
var greeting = ("Hello \(person)", language )
return greeting
}
let result = greeting("Tom")
Alec Holmes
2,035 PointsAlec Holmes
2,035 Pointsdidn't work...
Nevermind. There was a type in my greeting String. Thanks for you help!
Stone Preston
42,016 PointsStone Preston
42,016 PointsI just passed task 1 and 2 using the code above. Make sure you have everything typed/spelled correctly
Alec Holmes
2,035 PointsAlec Holmes
2,035 PointsYup that worked. I had a type in the greeting string. Thanks for helping!
Stone Preston
42,016 PointsStone Preston
42,016 Pointsno problem glad you got it figured out