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 Basics Swift Operators Operator Precedence

Berry Loeffen
Berry Loeffen
4,303 Points

about the 3%7 remainder. how come the answer is 3 as doesn't fit into 3 should it not be 0?

unclear how 3%7 equals 3 in stead of 0

1 Answer

Michael Reining
Michael Reining
10,101 Points

Hi Berry,

The answer is 3 because 7 does not fit into 3 as you said. Since it does not fit, you are left with everything (i.e. 3).

If you play in the playground in Xcode, you can see this yourself.

let answer1 = 3%2 // remainder = 1.  2 fits into 3 once and you are left with 1
let answer = 3%7 // remainder = 3.  7 does not fit so you are left with everything (3)

I hope that helps,

Mike

PS: Thanks to the awesome resources on Team Treehouse, I launched my first app.

Now you can practice writing Swift code directly on your iPhone :-)

Code! Learn how to program with Swift

Berry Loeffen
Berry Loeffen
4,303 Points

Thank you very much for the info!

well done on the app how long did it take you to make it. how many hour did you spend each day? :)