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 trialAdam Short
11,153 PointsHello, this challenge doesn't seem to be working. I have created some code that works in Xcode, but it won't accept it.
So I have created this: func greeting(person: String) -> (String, String) {
let GreetingTuple = (greeting: "Hello, \(person)", language: "English")
return GreetingTuple
}
This seems to fulfill all the requirements: It creates a tuple with both greeting and language, and returns them both in a single tuple. The code works fine in Xcode, but this challenge won't accept it. Why is that? Is it because I am initializing the names upon creation of the tuple (I tinkered with the code until I realized you could do this because its more compact.) and we haven't officially learnt that yet?
func greeting(person: String) -> (String, String) {
let GreetingTuple = (greeting: "Hello, \(person)", language: "English")
return GreetingTuple
}
2 Answers
Ethan Peacock
30 PointsHey it's not accepting your code because you aren't assigning the names it is asking for in the tuple that the function is supposed to return. You have -> (String, String) but you need to assign them the names in the challenge so it should be (greeting: String, language: String) leave the constants in the function and adjust what you are returning to also be a tuple so you should return (greeting, language) at the bottom of your function. It confused me too because of the redeclaration of greeting to so many different things but heres code that should complete the challenge, hope this Helps!
Ethan
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
Ethan Peacock
30 PointsNope, yours still would output (.0 "Hello, (person's name given when calling function)", .1 "English")
Its set up right just like my first attempt but the way the challenge grades your attempt i guess is very picky so you have to do it specifically the way it asks. Your code works the same, it just couldn't be graded because when the challenge was specifically looking for a name for the return type where your tuple was just (String, String), it wanted (greeting: String, language: String)
the only difference would be that in the example i showed you, when calling the function it shows you the parameter and their names instead of just (String, String)
copy the example code into a playground and try to call the function and you will see what I mean
Adam Short
11,153 PointsAdam Short
11,153 PointsIs the outcome different to mine? If so, what is the difference of outcome?