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.

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