Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Daniel Schlichter
783 PointsWhats wrong with my code?
I have no idea what could be wrong with my code.. can anybody help :/ ?
// Enter your code below
func getRemainder (value a : Int,divisor b : Int) -> Int {
let modulo = a % b
return modulo }
let result = getRemainder(a: 10, b: 3)
1 Answer

Steve Hunter
57,682 PointsHi Daniel,
You probably need to use the external names you created for each parameter. Also, while it isn't incorrect and won't fail the challenge, you can omit the constant that you immediately return from the function - just return the result of the expression directly:
func getRemainder(value a: Int, divisor b: Int) -> Int{
return a % b
}
let result = getRemainder(value: 10, divisor: 3)
I hope that helps,
Steve.
Steve Hunter
57,682 PointsSteve Hunter
57,682 PointsIf you click the 'Preview' button with your code, it'll point you in the direction of your error like this:
Daniel Schlichter
783 PointsDaniel Schlichter
783 Pointsthanks it works but its a bit strange because the same code with the exactly same function doesn't works at the playground
Steve Hunter
57,682 PointsSteve Hunter
57,682 PointsThe Playground has no idea what you are asked to achieve in the challenge. The tests behind the challenge compiler are specifically looking for adherence to the question as set; it is expecting you to use the argument labels. The Playground doesn't know that. The Playground will run code that is syntactically correct but which will still fail the challenge.
By way of example, this "passes" the challenge by returning the result expected for the challenge example but is clearly wrong despite
result
holding the correct value that the challenge is expecting. This works fine in the Playground as it is syntactically correct but, clearly, should not pass for Treehouse's purposes.Steve Hunter
57,682 PointsSteve Hunter
57,682 PointsThat said, in my Playground I get the same error.