## 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.

# Question about the PEMDAS formula Craig is explaining

Hey fellow coding students and teachers,

I don't really see how the „PEMDAS“ formula that Craig is presenting in the video is working in his example:

```10 - 3 * 5 + 8 = 3
```

I understand how the result is 3 by calculating

```(( 10 - ( 3 * 5 )) + 8 = 3
```

But according to the „PEMDAS“ formula the addition („A“) would have to be calculated before the substaction („S“).

So if this „PEMDAS“ formula would really be applied it should be:

```10 - (( 3 * 5 ) + 8) = -13
```

Or am I missing something?

Isn't it that addition and substraction are equal and will just be calculated in the order they appear (and not according to the PEMDAS order)?

Would be happy if someone could clear my confusion. Another way to think about it :

```10 - (3 * 5) + 8
10 - 15 + 8
-5 + 8
3
```

is really the same as:

```10 - (3 * 5) + 8
10 + (-(3*5)) +8
10 + (-15 + 8)
10 + (-7)
10 - 7
3
```

You can even change the order around so addition happens first:

```10 + 8 - 3 * 5
10 + 8 - (3 * 5)
10 + 8 - 15
18 - 15
3
```

The order of addition and subtraction actually doesn't matter at all, they are both considered 'commutative' operations.

I think piece that you were missing here is that the negative sign only applies to the value in the middle, it wouldn't be extended to the 8, even if doing that addition first:

The problem with this one is you have actually flipped the sign of the 8 when doing that operation and changed the value, not just did the operation first , even though it may not be obvious - if we have some fun with the distributive property, it should be clear this really is a different equation:

```10 - (( 3 * 5 ) + 8)
10 + ((-1) * ((3 * 5) * 8))
10 + (-1)*(3*5) + (-1)*(8)
10 - 3*5 - 8
10 - 15 - 8
-5 - 8
-13
``` Isn't it that addition and substraction are equal and will just be calculated in the order they appear (and not according to the PEMDAS order)?

Yes (MD and AS are equal and processed left to right)

Below is from Math is Fun

P - Parentheses first E - Exponents (ie Powers and Square Roots, etc.) MD - Multiplication and Division (left-to-right) AS - Addition and Subtraction (left-to-right)

Divide and Multiply rank equally (and go left to right).

Add and Subtract rank equally (and go left to right)

Thanks Dave!

Hi mate!, as far as i know in math u start substraction or addition for the left to the right, if it’s an + from the left u do this first, then the right side.

addition and substraction are equal , but u add or substract by which come first from the left side. first the (), than * /, and only then + - - this is the priority.

if this help mark as best answer

Thanks a lot, mate! PLUS

David O'Mahoney, I think addition and subtraction are equal to each other, but I depends on what has been entered first. go into repl and swap the plus and subtraction around. So I.e put your ''' 10 - ''' at the end and your '''+ 8''' at the beginning. You'll soon get your answer, I also find that learning from tutorial videos that tracing steps Is a good way to try to understand what you are not getting.

```8 + 3 * 5  - 10 = ?
```

I guess we can agree PEMDAS needs a facelift....(PE)(MD)(AS)