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

Aryaman Dhingra
Aryaman Dhingra
3,536 Points

Swift functions confusing me

I cannot understand where I'm going wrong. Please help debug my code.

functions.swift
// Enter your code below

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

1 Answer

andren
andren
28,558 Points

The issue is that you have the local and external parameter names the wrong way around. External parameter names comes first then the local name.

So you have to switch the names around like this:

// external and local name swapped
func getRemainder(value a: Int, divisor b: Int) -> Int {
  // value and divisor renamed a and b due to name change above
  return (a % b)
}