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 trial

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Build a Random Number Guessing Game

(2*3) + 2 * 6

the js console says this is = 18: not being brilliant in math by my calculations this should be 48...or maybe 38 ... but in no scenario can I imagine it would be 18.

5 Answers

Jeff Lemay
Jeff Lemay
14,268 Points

Order of Operations: Multiplication/Division then Add/Subtract

2*3 and 2*6 are run first regardless ( which then gives you (6) + 12 ). If you want it to get forty eight, you need:

(2 * 3 + 2) * 6

thank you jeff,

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

The way it works is the PEMDAS, or parentheses, exponents, multiplication and division, then addition and subtraction.

thanks caleb, yes I can see that now

so (2*3) + (2 * 6) is the same as 2*3 + 2*6

Thanks again jeff.