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

Emmanuel Darmon
Emmanuel Darmon
6,115 Points

func a modulo b

Cannot see what is wrong in Challenge Task 1. Here is my answer:

functions.swift
// Enter your code below

func getRemainder (a value: Int, b divisor: Int) -> Int {
    return value%divisor
}
Jeanne Merle
Jeanne Merle
3,390 Points

I would name variables with names without spaces, like this : func getRemainder (avalue: Int, bdivisor: Int) -> Int { return avalue%bdivisor }

Emmanuel Darmon
Emmanuel Darmon
6,115 Points

Nop... it seems the solution is:

functions.swift
func getRemainder (value a: Int, divisor b: Int) -> Int {
    return a%b
}

Thanks for your help!

2 Answers

Emmanuel Darmon
Emmanuel Darmon
6,115 Points

It seems the # are not necessary in this challenge, but you were right on the order and I understand the reason in the next task. Later, when you will use the function, you won't remember what is "a" and what is "b". Thanks to this number, xCode will remind you what are those values. Check this out:

functions.swift
// Enter your code below

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

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

Yes, that is the last line for the challenge and it highlights the reasons for using external values in function parameters (assuming you can't use better-named variables in the first place!).

Hi there,

I think the order needs to be altered a little in your function. Have a look at this:

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

That sets the external names (needing the # symbol) and internal ones too (a and b), then performs the mathematics on the internal values, returning the result required.

I hope that helps,

Steve.

Emmanuel Darmon
Emmanuel Darmon
6,115 Points

You right! Thanks for your help. But in the course video the exemple is:

functions.swift
func sayHello (to person: String, and anotherPerson: String) -> String {
    return Hello \(person) and \(anotherPerson)
}
sayHello(to: Pasan, and Gabe)

First, comes the short one "to", then it comes a longer name "person". And makes more sense this way, right?

Not sure of the precise reasons - I've never done that course. It is on the list! The example you've given does make total sense, yes! I'll have a look later to see if I can igure it out. It seems that the# symbol is dropped for external names to - maybe that's another Swift 2.0 change. Lots to look into!