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

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,526 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,526 Points

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