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 trialConor Quinn
3,461 PointsTrouble returning a tuple
I can't figure out whats wrong. The compiler says it can't convert type string to type (string, string). Please let me know what I'm doing wrong.
func greeting(person: String) -> (String, String) {
let language = "English"
let greeting = "Hello \(person)"
var sentence = (greeting, language)
return sentence
}
3 Answers
Holger Liesegang
50,595 PointsHi Conor Quinn !
Challenge Task 1 of 3 asks you: "Currently our greeting function only returns a single value. 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."
You forgot to name each item in the tuple like this: -> (greeting: String, language: String)
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
Misho Milicevic
5,597 Pointsyour function works on my playground... At the top did you import UIKit?
kjvswift93
13,515 PointsMy answer matches Holger's, at first glance.
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}