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 trialVikram Babu
2,158 PointsThe code I wrote returns an error even though there is no errors when pasted into the playground. Why?
The code attached is the code I copied into playground, an no errors resulted. Does anyone know why this is the case? Does anyone have suggestions as to what I can do to fix the errors in my code?
func greeting(#person: String) -> (greeting: String, language: String) {
let greeting = ("Hello \(person) ", "in English!")
return greeting
}
var result = greeting(person: "Tom")
1 Answer
Stepan Ulyanin
11,318 PointsTry making the greeting
a tuple of variables you want to return and return the whole tuple
func greeting(#person: String) -> (greeting: String, language: String) {
let greeting = "Hello \(person) "
let language = "in English"
return (greeting, language)
}
var result = greeting(person: "Tom")
Rehaan I
61 PointsRehaan I
61 Pointsswift var result = greeting(person: "Tom")
needs to be part of a function. Basically, any line of code should be in scope. So if you put the line of code in a function, it should run. For example:All you need to do now is to run the foo() function.