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

Tanner Hildebrandt
Tanner Hildebrandt
1,820 Points

Call the function and pass in a value of 10 for the first parameter and 3 for the second. Assign the result of

I have assigned the result a constant named result. What am I doing wrong here?

functions.swift
// Enter your code below
func getRemainder(value a: Int, divisor b: Int) -> Int {
let operation = a % b
return operation 
}

let result = getRemainder(value a: 10, divisor b: 3)

2 Answers

andren
andren
28,526 Points

When you call the function you should't specify both value and a as parameter names. value is the external label, meaning that is the label you use when you call the function. a is the internal label, meaning that is the one you use within the function. The same is true of divisor and b.

So if you simply remove a and b from the call to the function like this:

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

let result = getRemainder(value: 10, divisor: 3)

Then your code will work.