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 trialGabriel Kieruzel
Courses Plus Student 19,655 Pointsclosure
Hello,
I'm trying to go through the challenge. Anyway I'm not able to pass as the system has problems with my code while it apparently works as my playground does not have problems at all with my code. Please have a look and point , if possible what is not OK with my solution.
Regards.
/**
For this code challenge, letβs define a math operation as a function that
carries out some work on two integers and returns an integer as well. An
example is the function below, `differenceBetweenNumbers`, which takes two
integers and calculates the difference between the numbers. After calculating,
it returns the difference.
*/
func differenceBetweenNumbers(a: Int, b:Int) -> (Int) {
return a - b
}
// Enter your code below
func mathOperation (r: (c: Int, d: Int)->(Int), e: Int , f: Int) -> (Int) {
return r(c: e, d: f) as Int
}
1 Answer
mathiswiehl
7,133 PointsYou don't name the parameters of functions that you pass in to another. Accordingly, you don't you the names when you call them.
Also, you don't have to cast the result to Int because the function already returns an Int.
func mathOperation (r: (Int,Int)->(Int), e: Int , f: Int) -> (Int) {
return r(e,f)
}