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 trial

iOS Functions in Swift Adding Power to Functions Function Parameters

External And Local Function Parameter Names Not Passing

I can't for the life of me figure this one out. My code keeps failing saying I need to declare the correct external and local names.

My return clause currently uses the parameters "a" and "b", but I've also tried it with "value" and "divisor" and get the same error message

Any clues?

Cheers Don

functions.swift
// Enter your code below

func getRemainder(a value: Int, b divisor: Int) -> Int {
  return a % b
}

2 Answers

Chris Stromberg
PLUS
Chris Stromberg
Courses Plus Student 13,389 Points

Hint! In the code you provided above, you are giving an external name of "a" to the first parameter and "b" to the second parameter.

D'oh, getting my scope confused. That's what happens when you take on these things after 4 hours sleep

Me no function sleep well without :-)

Thanks for the help

Jack Baer
Jack Baer
5,049 Points

The code is fine. The problem is that you aren't doing what the challenge is asking - You aren't setting value and divisor as the external names. Here's the code that works. All I did was switch the placement of the parameter labels.

func getRemainder(value a: Int, divisor b: Int) -> Int { return a % b }

Hope this helps!

Thanks for the help Jack. I voted Chris's answer as "best" though as he just provided a clue, rather than write my code for me but your input is much appreciated :-)

Jack Baer
Jack Baer
5,049 Points

No problem :)

I've just found that some people prefer to be shown a solution if they're having trouble so they could compare code.

No problems at all, and thanks again :-)