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 trialJustus Aberson
1,035 PointsCan anyone help me out?
Hey guys, I was working on this question, and I just can't figure it out, I know it has something to deal with the print behind the cases, that I wrote. I just don't know how I can let it return to double, double. I hope someone can help me out! Thanks.
// Enter your code below
func coordinates(for location: String) -> (Double, Double) {
switch location {
case "Eiffel Tower": print(48.8582, 2.2945)
case "Great Pyramid": print(29.9792, 31.1344)
case "Sydney Opera House": print(33.8587, 151.2140)
default: print(0,0)
}
return ??
}
2 Answers
andren
28,558 PointsYour code is so close to being correct that giving you any real advice without straight out giving you the answer is actually pretty though. The thing I'll say is that the when the challenges states that it wants double, double returned it means that it wants the value you are currently printing returned. For example if the function was called with "Eiffel Tower" the challenge expects the exact value (48.8582, 2.2945) to be returned.
If you still want more specific advice just ask me.
Justus Aberson
1,035 PointsThanks for your reply! I still haven't figured it out so can you please say the answer? Thank you!!
andren
28,558 PointsSure, though I did try to give you a bit of a hint when I said "it wants the value you are currently printing returned", the hint being that simply changing your print statements to return statements would actually be all that was needed to complete the challenge.
func coordinates(for location: String) -> (Double, Double) {
switch location {
case "Eiffel Tower": return(48.8582, 2.2945)
case "Great Pyramid": return(29.9792, 31.1344)
case "Sydney Opera House": return(33.8587, 151.2140)
default: return(0,0)
}
}
While a function usually only has one return statement, having multiple ones is fine as long as there is some conditional logic that make it so that only one of them is executed when the function runs. The action performed by a switch case check is not limited to printing out a value, pretty much any single line expression can be executed, including return statements as you can see above.
Justus Aberson
1,035 PointsAhhh, I thought you could only have one return statement in a function, thanks a lot for helping me out!!
Justus Aberson
1,035 PointsJustus Aberson
1,035 PointsBtw, if you want to help me out, can you please not paste the right answer in? :P, but can you please send me a bit into the right direction? I really want to figure it out myself!