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
Rick Hoekman
9,494 PointsIt works within Xcode but I still get an error in the simulator that the result is wrong. Any suggestions?
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
let result = greeting("Tom")
3 Answers
Stone Preston
42,016 Pointsah . found the issue. the challenge states in task 1: Modify it to return both the greeting and the language as a tuple. Make sure to name each item in the tuple: greeting and language. We will print them out in the next task. so it seems to be expecting the greeting to come first in the tuple and the language second. so flip them around in your return type and in your return value.
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
Stone Preston
42,016 Pointstask 2 states Create a variable named result and assign it the tuple returned from function greeting. you created a constant using let. make it a variable by using var
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
var result = greeting("Tom")
Rick Hoekman
9,494 PointsThanks Stone, for the quick (or swift) reply!
I tried using 'var' before changing it to a constant. I changed it back again by using var but it is still not accepting.. :-/
Anthony Price
1,412 PointsI have the same problem as Rick and can't move forward....help.
Anthony Price
1,412 PointsHere is the answer:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
println(result.language)
Rick Hoekman
9,494 PointsRick Hoekman
9,494 PointsAh yes now it has accepted it as valid :-) Thanks for looking into this Stone!
Cheers!
Rick