## 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###### Unsubscribed User

**Front End Web Development**Techdegree Student 33,900 Points

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

You get an upvote for sure for your answer. :-)

## 5 Answers

###### Dave StSomeWhere

19,870 PointsIsn'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)

###### Unsubscribed User

**Front End Web Development**Techdegree Student 33,900 Points

Thanks Dave!

That's really clear an helpful.

###### mohan Abdul

Courses Plus Student 1,453 PointsDave StSomeWhere hi, so what you are saying addition and subtraction are equal and will be executed in the order they appear in? please reply I am counting on you.

###### David O'Mahoney

869 PointsWhat you have said is very clear, does this mean that what Craig said in the video is incorrect then? As I found this very confusing, he seemed to ignore the rule he had just given to us.

###### <noob />

17,061 PointsHi 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

###### Unsubscribed User

**Front End Web Development**Techdegree Student 33,900 Points

Thanks a lot, mate!

###### mohan Abdul

Courses Plus Student 1,453 PointsDavid 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 = ?
```

###### christian garea

2,641 PointsThanks for asking this I had the exact same question he should of explained this

###### Oren Schindler

2,166 PointsI guess we can agree PEMDAS needs a facelift....(PE)(MD)(AS)

## Hambone F

3,581 Points## Hambone F

3,581 PointsAnother way to think about it :

is really the same as:

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

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

onlyapplies 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: