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

Functions swift code challenge 1

Challenge Task 2 of 2

Now that we have a working function let's use it.

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

Assign the result of the function operation to a constant named result.

Bummer! You need to assign the result of the function evaluation to the constant named result

I don't understand the error. I used let to assign the constant result to the function but maybe this is not how it goes.

Thanks.

functions.swift
// Enter your code below
func getRemainder(value a: Int, divisor b: Int) -> (Int) {

  var remainder = a % b

  return remainder
}

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

1 Answer

Matthew Long
Matthew Long
28,383 Points

You did everything correct except the return type isn't what the code challenge is expecting? I copied your code into Xcode, and it still works. That's all I can find "wrong" with your code. It's not usual to use the parentheses as a return type unless you're returning a tuple though. So if you remove the parentheses around (Int) you'll pass the challenge:

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

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