Calculator project operator precedence question

Calculator project operator precedence question
0.0 0

#1

In the example codepen project link for the javascript Calculator project, if you enter 4+4*10 the result is 80! Without parentheses, multiplication has precedence over addition, so 4+4*10 is 44, correct? Currently, my Calculator works according to what I think is the ‘normal’ operator precedence, given that we don’t have parentheses.
Should I change this so that it works like the example project on codepen? I really think the codepen example is wrong. What should I do?
-Ben


#2

I have seen it done both ways. The 4 + 4 * 10 = 80 is a throwback to handheld calculators that worked like that; sequentially like adding machines. But I’ve also seen folks building the statement and then evaluating it which accounts for precedence and gives you 44.

I did mine the first way,since the overall intent seemed to be to emulate an old fashioned hand calculator.

But I think the way the stories are written it’s open to some interpretation. It’s a good question to ask. In the end if you make a decision and learn to implement it then I think the spirit of the challenge is met. That’s no more than one personal opinion.


#4

Thanks! I was worried, because one of the user stories is: “I can keep chaining mathematical operations together until I hit the equal button, and the calculator will tell me the correct output”. I was like, whoa, what’s “correct”, then :slight_smile:
Thanks, again!
-Ben


#5

Exactly! I had the same reaction :slight_smile: