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 trialNACHO MERINO
1,216 PointsFunctions swift code challenge 1
Challenge Task 2 of 2
Now that we have a working function let's use it.
Call the function and pass in a value of 10 for the first parameter and 3 for the second.
Assign the result of the function operation to a constant named result.
Bummer! You need to assign the result of the function evaluation to the constant named result
I don't understand the error. I used let to assign the constant result to the function but maybe this is not how it goes.
Thanks.
// Enter your code below
func getRemainder(value a: Int, divisor b: Int) -> (Int) {
var remainder = a % b
return remainder
}
let result = getRemainder(value: 10, divisor: 3)
1 Answer
Matthew Long
28,407 PointsYou did everything correct except the return type isn't what the code challenge is expecting? I copied your code into Xcode, and it still works. That's all I can find "wrong" with your code. It's not usual to use the parentheses as a return type unless you're returning a tuple though. So if you remove the parentheses around (Int)
you'll pass the challenge:
func getRemainder(value a: Int, divisor b: Int) -> Int {
var remainder = a % b
return remainder
}
let result = getRemainder(value: 10, divisor: 3)