• Home
  • Blog
  • JavaScript program help – Create Stack Computer from Stack

JavaScript program help – Create Stack Computer from Stack


Hi, I need help creating JavaScript code to perform the instructions as outlined below. The word document also contains the base code I have so far. This code will require additional logic and functions in order to work per instructions.

Implement a Stack in Javascript. Do not use an array as the stack or in the implementation of the stack. Repeat – You MUST implement the Stack (start with your linked list) without the use of an array..

You will build a Stack Computer from your stack. When a number is
entered it goes onto the top of the stack. When an operation is entered,
the previous 2 numbers are operated on by the operation and the result
is pushed onto the top of the stack. This is how an RPN calculator.

For example

2 [enter] 2

5 [enter] 5 2

* [enter] * 5 2 -> collapses to 10

would leave at 10 at the top of the stack.

The program should use a simple input box, either a text field or prompt and display the contents of the Stack.

[Push to Stack]

Contents of Stack:

NOTE: Implementation of a Stack using an array will not be accepted. A stack computer created using a Stack (with correct
push and pop) that performs all operations correctly – and does not
allow bad entries (non-numeric or operation, no operations until 2
numbers on stack) is what I am looking for.


About the Author

Follow me

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}