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!
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
Alison KingiOS Development with Swift Techdegree Student 424 Points
in the following calculation:
let someOperation = 20 + 400 % 10 / 2 - 15
is the order of the arithmetic operators 420 divided by 5 (ie 10 over 2) and then minus 15? or 42 divided by -13 (ie 2-15)?
What are the rules as in algebra there would be brackets to specify order of the calculations
// Enter your code below let value = 200 let divisor = 5 let someOperation = 20 + 400 % 10 / 2 - 15 let anotherOperation = 52 * 27 % 200 / 2 + 5 // Task 1 - Enter your code below let result: Double = value % divisor // Task 2 - Enter your code below
Alex KoumparosPython Development Techdegree Student 36,886 Points
Apple has a page showing operator precendence.
As per that article, the order of operations is:
10 / 2 // 5 400 % 5 // 0 20 + 0 // 20 20 - 15 // 5
Like in regular algebra you can use parentheses to override the built-in operator precedence.
Hope that helps