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 trialRobin Malhotra
14,883 PointsWorking in Xcode, not in challenge.
Here's my code that's working with the simulator.
func differenceBetweenNumbers(a: Int, b:Int) -> (Int)
{
return a - b
}
func mathOperation (operation:(Int,Int)->Int,a:Int,b:Int)->(Int)
{
return operation(a,b)
}
let difference = mathOperation(differenceBetweenNumbers,a: 4,b: 2)
1 Answer
Jhoan Arango
14,575 PointsHello
Simple fix.. take the () off your return.
func mathOperation (operation:(Int,Int) -> Int, a:Int, b:Int) -> Int {
return operation(a,b)
}
Robin Malhotra
14,883 PointsRobin Malhotra
14,883 PointsWait, what? I still don't get how that makes a difference. I mean, differenceBetweenNumbers has brackets on the return type.
Jhoan Arango
14,575 PointsJhoan Arango
14,575 PointsIt does not make sense, I know that in Xcode does work, but for some reason on the challenge if you use the () on the return it does not pass the challenge. I knew you had that mistake because I have seen it a million times on other students asking the same question, and they happen to pass the challenge without em. Also I just notice something else that won't let your challenge pass..
Take the parameter names off when calling the function
let difference = mathOperation(differenceBetweenNumbers, 4, 2)
Good luck ~