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 trialBen Masel
2,004 PointsI Don't Really Know What I'm doing!
Please tell me what i have done wrong, how to correct my mistakes and what I've forgot!
// Enter your code below
func getTowerCoordinates(Landmarks: String) -> (lat: Int, Lon: Int) {
switch Landmarks {
case "Eiffel Tower": "48.8582,2.2945"
case "Great Pyramid": "29.9792,31.1344"
case "Sydney Opera House": "33.8587,151.2140"
default:
}
return getTowerCoordinates("Null")
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi again Benjamin Masel! Well, you aren't the first one to get stuck on this challenge, I promise you. For some reason there seems to always be some confusion when moving from if/else statements over to switch statements. Keep in mind that anything that can go in an if/else statement can go in the body of a case statement. But let's take a harder look at your code.
The challenge asks you to return two doubles. But your function is set up to return two integers. It also explicitly states to return the points (0,0) in the default case, but your default is completely empty. And, in fact, the only return statement you have anywhere will return Null
. There's no other return statement anywhere. But even if you added the return
in front of all those coordinates right now, it still wouldn't work. Remember, the quotes make them strings Take a look at my solution and see if it makes sense.
// Enter your code below
func getTowerCoordinates(Landmarks: String) -> (Double, Double) {
switch Landmarks {
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, 0.0)
}
}
This code looks at the Landmarks
variable. It then goes through and sees if it has a match. If it does, it returns the coordinates as a tuple containing two Double
values. Remember, a function will cease to execute once a return statement is reached. Hope this helps!
Ben Masel
2,004 PointsBen Masel
2,004 PointsThank you! and yes i get it completely! but it says that:
Ben Masel
2,004 PointsBen Masel
2,004 PointsI've tried returning some things but it still can't be compiled!
Ben Masel
2,004 PointsBen Masel
2,004 PointsGot it! You forgot to return a double value in getTowerCoordinates i did: (0.0,0.0)