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 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? :)