Calculator Class
Methods and properties for the reverse-polish calculator. Example instantiation using default display element ids:
var calc;
window.onload = function () {
calc = new Calculator();
};
Constructor
Item Index
Methods
Properties
Methods
addToStackDisplay
-
item
Adds item to the stack display's inner HTML.
Parameters:
-
item
MixedNumber | String
Returns:
clearAll
()
Void
Clears the display elements and the program stack.
Returns:
clearStackDisplay
()
Void
Clears the stack display element.
Returns:
digitPressed
-
d
Handles the click event on digit keys.
Parameters:
-
d
MixedNumber (0-9) | String (".")
Returns:
displayStack
()
Void
Loops through the stack and outputs the values to the stack display.
Returns:
enterPressed
()
Void
Event handler for clicks on the enter key.
Returns:
operatorPressed
-
o
Handles the click event on operator keys (+ - * / etc.).
Parameters:
-
o
String
Returns:
undo
()
Void
Clears the last item input: if digits being entered then backspace one digit else clear last item from stack and re-run program.
Returns:
Properties
display
HTMLElement
The element in which calculation results are displayed.
Default: "rpnc_display"
isUserEnteringDigits
Boolean
Indicates whether the user is in the process of entering digits.
Default: false
stackDisplay
HTMLElement
The element in which the contents of the stack are displayed.
Default: "rpnc_stack"