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

john vallone
john vallone
890 Points

Using functions

I declared my function... named my parameters (both internal and external)... returned an integer... setup my modulo equation... and returned the "remainderOfValue".

Then I called the function getRemainder.

It works in Xcode and delivers "2" with no errors but still seems to be incorrect here. Just checking to see if anyone can help. Thank you.

functions.swift
// Enter your code below
func getRemainder (a value: Int, b divisor: Int)-> Int {
  let remainderOfValue = value % divisor 
  return remainderOfValue
}

getRemainder(a: 6, b: 4)

1 Answer

Logan R
Logan R
22,989 Points

You're super close! You have your names flip-flopped. It should instead be:

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

getRemainder(value: 6, divisor: 4)

The first part is the name of the named parameter, the second part is the local variable name.

john vallone
john vallone
890 Points

:).... Thank you Logan!

Logan R
Logan R
22,989 Points

Not a problem! If you have any further issues or questions, feel free to post them on the forums :D