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 Swift 2.0 Functions Function Parameters Function Parameters

Function for named parameter

What's wrong with this? It works in playground, but not in the challenge.

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.

/Users/mattconway/Desktop/Screen Shot 2016-01-18 at 3.58.29 PM.png

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

2 Answers

Hi Matt,

I'm answering this on my phone so I have a restricted view. Apologies.

I'm not sure why you are calling your getRemainder function from inside itself; I'd delete that line.

And outside the function, you've called a function called getReminder; I'd change that too. Typo! :-)

Let me know how you get on. I hope that helped.

Steve.

Nathan Tallack
Nathan Tallack
22,159 Points

You were close. Consider your fixed code below with the comments inline.

// Enter your code below
func getRemainder(value a: Int, divisor b: Int) -> Int {
  return a % b
  // No need for this last line in your function.
}

// Constant is to be named result not results
// You had a typo in your function name.  Missing the "a".
let result = getRemainder(value: 10, divisor: 3)

Keep up the good work! :)

Ryan Rassoli
Ryan Rassoli
3,365 Points

Why are your not putting value a and divisor b in the result?