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 trialkirkbyo
15,791 PointsTrouble computing the difference between two integers.
I am having trouble locating where I went wrong with task 2 of this challenge.
Questions:
Using the differenceBetweenNumbers function as an input to mathOperation, compute the difference between any two integers and assign the result to a constant named difference.
Error:
Bummer! Make sure you are computing the difference between two integers using the functions created and assigning the result to a constant named difference.
My Code:
func differenceBetweenNumbers(a: Int, b:Int) -> (Int) {
return a - b
}
func mathOperation(mathFunc: (Int, Int) -> (Int), a: Int, b: Int) -> Int {
return mathFunc(a, b)
}
let difference = mathOperation(differenceBetweenNumbers, 20, 10)
Ozzie
1 Answer
agreatdaytocode
24,757 PointsYour code looks fine. This worked for me. I used someOperationFunc(a,b)
func mathOperation(someOperationFunc: (Int, Int) -> Int, a: Int, b: Int) -> Int {
return someOperationFunc(a, b)
}
let difference = mathOperation(differenceBetweenNumbers, 26, 22)
kirkbyo
15,791 Pointskirkbyo
15,791 PointsThe error was caused by having the function parameter return being wrapped in parathesis.
Anyways, thanks for your help!
Ozzie
Wei Wen
2,995 PointsWei Wen
2,995 PointsWhat is the difference between Int and (Int)?
Nehemiah Reese
17,692 PointsNehemiah Reese
17,692 PointsWhy isn't it:
let difference = mathOperation(differenceBetweenNumbers() , 26, 22)
Is the function a constant being passed in?