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 trialTERRELL TINSLEY
2,964 PointsWhy won't this work?
Can some one explain to me why this code wouldn't work during the quiz but it works in my playground? And is the other way better than the way I did it? If so can you explain why.
func getTowerCoordinates(location: String) -> (Double, Double) {
var coordinates: (Double, Double)
switch location {
case "Eiffel Tower": coordinates = (48.8582, 2.2945)
case "Great Pyramid": coordinates = (29.9792,31.1344)
case "Sydney Opera House": coordinates = (33.8587, 151.2140)
default: coordinates = (0, 0)
}
return coordinates
}
getTowerCoordinates("Eiffel Tower")
5 Answers
Marina Alenskaja
9,320 PointsThe challenge says you have to be able to pass in a landmark and have the coordinates be returned to you - which is why your answer didn't pass, since it only returns all the coordinates for all the landmarks instead. Hope that makes sense :-)
Marina Alenskaja
9,320 PointsHi! Here is my answer - maybe that will help you see where the error is?
func getTowerCoordinates(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)
}
}
getTowerCoordinates("Eiffel Tower")
Adam Beck
9,345 PointsThanks for posting this, it works! I was thrown off because I have never seen the instructor use the 'return type' like that! Arg! Learned something new..
Marina Alenskaja
9,320 Pointsoh and the -> is of course my arrow ->
TERRELL TINSLEY
2,964 PointsI figured out the "correct" answer. I just didn't understand why the way I did it wasn't being accepted, but I get the same result. Thanks though!
TERRELL TINSLEY
2,964 PointsAhhh yes, that does make sense. It's always the small things that trip you up when programming. Thanks again.
Evgeny Nagimov
4,075 PointsEvgeny Nagimov
4,075 PointsYou did everything correct. Just the last line of code shouldn't be there. Delete it and that's it!
func getTowerCoordinates(location: String) -> (Double, Double) {
}