# Calculator - feedback

Hi :), I finished the basic functionality of a simple calculator (I still have to work on the design). Any feedback is appreciated.

• project:

https://github.com/diegoperezm/calculator/

• demo:

https://diegoperezm.github.io/calculator/

#### some comment about the code

I am using a statechart, so in order to avoid “too many arrows” I am using a “type” plus “data” approach.
The idea is use only seven events(“types”) and use “data” to specify a value:

• number
• zero
• ce
• dot
• operator
• minus
• equals

Using this approach the number of arrows is reduced from 17 to 7.

The statechart code is imperative and easy to follow.
Most of the operations are simple assignments with the exception of:

• User Story #13: state: OPERATORENTERED

If 2 or more operators are entered consecutively, the operation performed should be the last operator entered (excluding the negative (-) sign). For example, if 5 + * 7 = is entered, the result should be 35 (i.e. 5 * 7); if 5 * - 5 = is entered, the result should be -25 (i.e. 5 x (-5)).

• User Story #6: state: START,RESULT,OPERAND1, OPERAND2,OPERATORENTERED,NEGSTART,NEGOPERATOR.

My calculator should contain an element to display values with a corresponding id=“display”.

Where is used the (array) pop method (OPERATORENTERD) and the functions displayData, displayResult and calculate (respectively).

I think that add other functions (or other layer of abstraction) can make the code harder to read.

#### todo

• [0/2] Limit the number of characters in display:

• Make more explicit the this feature (maybe using the extended state/context)
• The numbers of characters should vary according to how much space is left in the display
• [0/1] Division by 0 currently ‘NaN’:

• change it for an error message or something else?
• [0/2] Test cases:

Cheers and happy coding 