0
AC
←
7
8
9
÷
4
5
6
×
1
2
3
-
0
.
=
+
This web app follows Project: Calculator from The Odin Project, including all extension criteria (except making it look nice, but maybe I'll do that later!).
All core features from assignment specification:
- Operations are strung together, evaluating from left to right. E.g. 12 + 7 - 5 * 3 = eventually evaluates to 42.
- Numbers are rounded to fit on screen. User cannot input more than the screen size. Very large/small numbers are represented using scientific notation. The negative sign is also taken into account.
- Pressing the = button twice in a row does nothing.
- NaN output (such as dividing by zero) puts the calculator into an error state that can be cleared using the AC button.
- The decimal point button can only be used once per number.
-
Keybinds implemented:
0-9,
,,
.,
+,
-,
*,
x,
/,
\,
=,
enter,
escape,
ctrl + z, and
backspace.
Additional features:
- Pressing - before a number is entered will make the number negative.
- Pressing +, ×, or ÷ before a number is entered will reuse the existing "current number". (This behaviour may be a bit confusing to use though since there's a delay in seeing the number.)
- Keyboard presses will also highlight the key pressed in the UI.
Issues with this implementation:
- I'm relying on the Javascript Number implementation for numerical precision, which is represented using IEEE 754 double-precision floating point. This may have undesirable behaviour compared to BCD (binary-coded decimal), particularly around digits to the right of the decimal point. I haven't looked into how to mitigate these issues, and I don't know of any examples where these precision issues show up in this calculator. I'm not going to bother since this is meant to be a simple web development exercise.
- I didn't really try too hard to make this app render well on all platforms. This app was developed using Google Chrome on a minimally-customized Windows 10 system.
- The code is hard to read. I'll need to figure out how to untangle it.