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 trialShukran Ali
132 PointsIf in the order of operations addition comes before substraction, why didnt you add 15 with 8 first then do 10 - 23?
If in the order of operations addition comes before substraction, why didnt you add 15 with 8 first then do 10 - 23?
5 Answers
Joseph Yhu
PHP Development Techdegree Graduate 48,638 PointsAddition does not come before subtraction in the order of operations. They have the same precedence, so the expression will be evaluated from left to right.
Master ohm
40 Pointswhich ever you consider , I consider BODMAS , so addition definately comes before substraction.
nicolaspeterson
8,569 PointsHey Joseph could you elaborate more on this? I'm still confused even after reading your explanation, and the link in the teacher's notes didn't help.
Joseph Yhu
PHP Development Techdegree Graduate 48,638 PointsTo use his example: 10 - 15 + 8, you would do the subtraction first because it comes before the addition (i.e. 15 + 8) and addition and subtraction have the same precedence.; however, if the expression was, e.g.: 10 - 15 * 8, you would do the multiplication first because multiplication has higher precedence over subtraction.
It's helps to understand if you remember that subtraction is simply addition by a negative: 10 - 15 + 8 is the same as 10 + (-15) + 8.
Team Matrix
Courses Plus Student 456 Pointsparenthesis is most powerful then exponents. Division and multiplication has same precedence. Addition and subtraction has same precedence. In case of same precedence, which operator comes first will be executed first.
ja5on
10,338 PointsI have this technique from https://www.mathsisfun.com/operation-order-bodmas.html
basically
B Brackets first
O Orders (i.e. Powers and Square Roots, etc.)
DM Division and Multiplication (left-to-right)
AS Addition and Subtraction (left-to-right)
Note: the only strange name is "Orders". "Exponents" is used in Canada, and so you might prefer "BEDMAS". There is also "Indices" which makes it "BIDMAS". In the US they say "Parentheses" instead of Brackets, so it is "PEMDAS"
Shukran Ali
132 PointsShukran Ali
132 PointsOh okay thanks because he said in PEMDAS addition comes first had me confused