JavaScript Calculator
|
  |
Assignment extra credit
Solution notes:
- Uses the eval() method to evaluate the answers
- Attempts to simulate a real calculator. After pressing an operation key (+ - / *) the calculator display is cleared. The current value and the operator are stored in global JavaScript variables. After entering the next numeric, and pressing another operation key, or the equals key the result is evaluated.
- You can also enter values directly into the calculator display (answer) field. If these are non-numerics it will tell you; the onKeyUp method performs a KeyCode check on the values entered (NOTE: Works with InterNet Explorer only, not quite worked out Netscape!)
- Be consistent, either type values or use the key pads.
- To type values enter then number, then hit the operator (+ - / *), then hit the second number, then either hit the eqauls button, or another operator with further numbers etc.
- To enter a Decimal number using the keypads input zero first (e.g 0.25), the number .25 can not be entered. Nor can two full stops
- The result of the previous calculation is retained, you can do for example 1 + 2 + 3 + 4 = to get 10
- Uses OnClick and onReset and some functions. onSubmit has not been used as there is no action behind the form.
- The code does not past the W3C validator. The HTML FORM tag requires the ACTION and ID attributes and the NAME attribute is not recognised? JavaScript does not recognise ID! Most odd? Marshall??????
|