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 trialEmmanuel Darmon
6,115 Pointsfunc a modulo b
Cannot see what is wrong in Challenge Task 1. Here is my answer:
// Enter your code below
func getRemainder (a value: Int, b divisor: Int) -> Int {
return value%divisor
}
Emmanuel Darmon
6,115 PointsNop... it seems the solution is:
func getRemainder (value a: Int, divisor b: Int) -> Int {
return a%b
}
Thanks for your help!
2 Answers
Emmanuel Darmon
6,115 PointsIt 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:
// Enter your code below
func getRemainder (value a: Int, divisor b: Int) -> Int {
return a%b
}
let result = getRemainder(value: 10, divisor: 3)
Steve Hunter
57,712 PointsYes, 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!).
Steve Hunter
57,712 PointsHi 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
6,115 PointsYou right! Thanks for your help. But in the course video the exemple is:
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?
Steve Hunter
57,712 PointsNot 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!
Jeanne Merle
3,390 PointsJeanne Merle
3,390 PointsI would name variables with names without spaces, like this : func getRemainder (avalue: Int, bdivisor: Int) -> Int { return avalue%bdivisor }