This is my first calculator written in JavaScript. Fully independent item, not based on any internet examples. It works fine now, but there's still some probability of errors hard to reproduce.
Design is non sequential; that means user should write all his calculations, and later click [ Calculate ] button. Input after sanitation is shown on top strip as a "Calculation done:", and result on a main field. If there's not enough data in input, error info is displayed on top strip.
Info
- Dividing by zero is illegal, and not supported.
- All division results, and final result are rounded to fifth position after the dot.
- Only the last one operator is counted, except situation when the last one is minus, so...
- If the last one operator is minus, then next number is negative, and the previous one operator is counted, except situation when the minus is the only one, so...
- If the minus is the only one, this is just the minus, except the situation when that minus is before the first number, so...
- If the minus is the only one (or the last in a row) operator before the first number it changes sign of that number to negative. Simply.
- Dot is a decimal. All dots from the beginning of a number are removed, so .1 is just a 1 not 0.1, as one could expect. Only the first dot in a number is counted, the second one and all signs after it are deleted.
ToDo
- OOP it.
- Firefox cant into divs as a buttons, why?
- Result is removed if operator is clicked, maybe it should be that way.
- More operators, and functions, less code.
- Nicer design.