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 trialPaul Je
4,435 PointsCopied it right off of the doc, but to no avail
Can't seem to get it right, I just noticed the line in the document on Apple's site. But still not working.. Any help would help a lot lol
/**
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(differenceBetweenNumbers: (Int, Int) -> Int, _ a: Int, _ b: Int) {
print(differenceBetweenNumbers(a, b))
}
mathOperation(differenceBetweenNumbers, 5, 3)
2 Answers
Anjali Pasupathy
28,883 PointsYou're nearly there! You just need to return the result of applying differenceBetweenNumbers, rather than printing it.
func mathOperation(differenceBetweenNumbers: (Int, Int) -> Int, _ a: Int, _ b: Int) { // return an Int value
print(differenceBetweenNumbers(a, b)) // return this value rather than printing it
}
I hope this helps!
Paul Je
4,435 PointsOkay just followed Anjali's suggestion and got the answer! This one was weird to format but finally got it haha
Anjali Pasupathy
28,883 PointsI'm glad I could help!
jcorum
71,830 Pointsjcorum
71,830 PointsAnjali, did you try your code in the challenge?
When I run your code I get: Bummer! Make sure your function is named
mathOperation
and check your parameters and return type!Anjali Pasupathy
28,883 PointsAnjali Pasupathy
28,883 PointsI didn't post working code. I posted Paul's code with instructions in comments on how to turn it into functional code. If you follow those instructions (returning an Int value in the function header, and returning the value in the print statement rather than printing that value), the resulting code should work in the challenge.