iOS Functions in Swift Adding Power to Functions Function Parameters

Elizabeth Hernandez
Elizabeth Hernandez
1,207 Points

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,342 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.

Elizabeth Hernandez
Elizabeth Hernandez
1,207 Points

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

Elizabeth Hernandez
Elizabeth Hernandez
1,207 Points

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

andren
andren
28,342 Points

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