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

I can't get passed Step 1 for this code challenge and I'm not sure why. No code errors show in preview

Code: func getRemainder(a value: Int, b divisor: Int) -> Int {

let result = value % divisor
return result

}

Instructions don't state a variable name for the result, but if there's nothing noted within the function the test fail. It's not clear if any specific code is desired within the function as long as the result is correct. I'm not sure why this is failing. As noted, preview returns no errors and the code works in my Xcode playground as well.

functions.swift
// Enter your code below


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

  let result = value % divisor
  return result

}

1 Answer

andren
andren
28,558 Points

The challenge specifies that you should have a and b as the parameter names and value and divisor as the external parameter names. You have them the wrong way around.

If you swap them like this:

func getRemainder(value a: Int, divisor b : Int) -> Int { // Swapped local and external parameter names
  let result = a % b  // Changed names to account for the changes above
  return result
}

Then your code will be accepted.

Nvm. I figured out what they wanted. I see now I reversed the internal and external parameters names requested ;P

Thanks for the quick reply andren. Yeah, I figured it out after I posted this :)

andren
andren
28,558 Points

No problem, it's an easy thing to overlook :smile:.