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 trialDaniel Gross
2,545 PointsI don’t understand what i’m doing wrong here.
They asked for
- a function called “mathOperation”
- Two variables of Int type
- a return type of Int
- and to return the result of a math function with those integers.
Where did i go wrong
func mathOperation (a: Int, b: Int) -> (Int) {
return a + b
}
2 Answers
Sara Chicazul
7,475 PointsRead the challenge again:
"Write a function called mathOperation that takes a math operation (as defined in the editor) as the first input, two integers on which we carry out the math operation, and a return type of Int. The body of the function simply returns the result of the math operation you pass in. Note: We are attempting to build a higher order function so your first parameter must be a function. If you're having trouble, read the Function Types as Parameter Types section in the docs"
See that? Your first parameter must be a function. mathOperation
should have three parameters. Instead of picking a random math operation to perform on the two integers, you should use the function supplied as the first parameter. An example of this is in the linked documentation if you're having trouble!
Khairul Akmal
Courses Plus Student 16,527 PointsHere's an example from the Swift documentation
Hope it helps :)