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

Code Challenge: What is wrong? Or what am I missing?

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

getRemainder("value", b: "divisor")

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Unfortunately, you haven't included a link to the challenge. However, what I can tell you thus far is that you're calling the getRemainder function. This function accepts two integers. But what you're sending in is two strings. Not knowing which challenge this is, it's unclear if the instructions instruct you to call the function yourself or not. Hope this hint helps! :sparkles:

Yeah, I'm guessing the challenge has him assigning integers to variables like so.

var value = 3
var divisor = 11

getRemainder(value, b: divisor)

Don't use quotes, Jacob.

Ah, found the challenge. It's about internal and external parameter names. Jacob, when you declare a function in Swift, you can specify internal and external parameter names. These can drastically increase readability, and are separated by a space. Try declaring the function like this:

// The external parameter names are 'value' and 'divisor', while the internal parameter names are 'a' and 'b'.
// We use the internal parameter names in the implementation...
func getRemainder(value a: Int, divisor b: Int) -> Int {
  return a % b
}

// Then use the external parameter names 'value' and 'divisor' to call the function
let result = getRemainder(value: 10, divisor: 3)

Thanks for this!