Error in Build a JavaScript Calculator

Error in Build a JavaScript Calculator
0

#1

Hi campers,
I don’t know if it has been pointed out, but in this project https://codepen.io/freeCodeCamp/full/rLJZrA from this challenger https://www.freecodecamp.org/challenges/build-a-javascript-calculator , the calculator has an error. Here the error:
Calcolatrice_codePen

I wrote 2x3+3x2 and the result should be
12, but this give me 18.


#2

It is not “wrong”, but it does not calculate using immediate execution logic vs formula logic as you are doing when you get 12. This calculator is simply processing the calculations based on the order in which they appear. So, 2x3 is first which is 6, then the + 3 which makes it 9, then * 2 which makes it 18. The challenge instructions do not specify which logic to use, so you are free to choose which method you want. The upcoming Beta version of this challenge actually explains the two versions and let’s you pick one.


BUG in Demo app: Build a JavaScript Calculator
#3

@RandellDawson
Add “( )” ad every step would formally solve the problem that is just in the writing “2x3 + 3 x 2 = 18”. Writing “(((2x3)+3)x2) = 18” it’s formally correct.


#4

Also, using immediate execution logic, like I said previously will also generate 18 as the answer. You can implement the calculator with which ever logic version you want, but just be consistent in your implementation and do not mix the two logic versions when making calculations.


#6

it’s pretty funny btw that the win7 calculator considers that 1 + 2 * 3 = 9 if it’s in the standard mode while in the scientific and programmer modes it considers that 1 + 2 * 3 = 7

i think since we should make a rather simple calculator, immediate execution makes more sense. it’s also a bit easier to code :3