API Docs for: 1.0.0
Show:

Calculator Class

Defined in: calculator_v2.js:4
Module: Calculator

Methods and properties for the reverse-polish calculator. Example instantiation using default display element ids:

 var calc;
 window.onload = function () {
   calc = new Calculator();
 };

Constructor

Calculator

(
  • [options]
)
Void

Defined in calculator_v2.js:4

Parameters:

  • [options] Object optional
    • [displayId] String optional

      Element id for the display field; default=rpnc_display.

    • [stackDisplayId] String optional

      Element id for the stack display field; default=rpnc_stack.

Returns:

Void:

Methods

addToStackDisplay

(
  • item
)
Void

Defined in calculator_v2.js:55

Adds item to the stack display's inner HTML.

Parameters:

  • item Mixed

    Number | String

Returns:

Void:

clearAll

() Void

Defined in calculator_v2.js:70

Clears the display elements and the program stack.

Returns:

Void:

clearStackDisplay

() Void

Defined in calculator_v2.js:82

Clears the stack display element.

Returns:

Void:

digitPressed

(
  • d
)
Void

Defined in calculator_v2.js:91

Handles the click event on digit keys.

Parameters:

  • d Mixed

    Number (0-9) | String (".")

Returns:

Void:

displayStack

() Void

Loops through the stack and outputs the values to the stack display.

Returns:

Void:

enterPressed

() Void

Event handler for clicks on the enter key.

Returns:

Void:

operatorPressed

(
  • o
)
Void

Handles the click event on operator keys (+ - * / etc.).

Parameters:

Returns:

Void:

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:

Void:

Properties

display

HTMLElement

Defined in calculator_v2.js:23

The element in which calculation results are displayed.

Default: "rpnc_display"

isUserEnteringDigits

Boolean

Defined in calculator_v2.js:31

Indicates whether the user is in the process of entering digits.

Default: false

program

Program

Defined in calculator_v2.js:39

Instance of Program class.

stackDisplay

HTMLElement

Defined in calculator_v2.js:46

The element in which the contents of the stack are displayed.

Default: "rpnc_stack"