Question: Why can I not enter operand into the input box so that the last two numbers in the stack get added, subtracted, divided, or multiplied
Why can I not enter operand into the input box so that the last two numbers in the stack get added, subtracted, divided, or multiplied by their respective operands Also combine the push to stack function and evaluate function into one function. I will thumbs up if the code works!
RPN Calculator
class Node
constructordata
this.data data;
this.next null;
class Stack
constructor
this.top null;
pushdata
const newNode new Nodedata;
newNode.next this.top;
this.top newNode;
this.display;
pop
if this.top
this.displayOutputStack is empty";
return null;
const poppedData this.top.data;
this.top this.top.next;
this.display;
return poppedData;
display
let current this.top;
const stackContents ;
while current
stackContents.pushcurrentdata;
current current.next;
this.displayOutputContents of Stack: stackContents.join;
displayOutputmessage
document.getElementByIdstackOutputinnerText message;
const stack new Stack;
function pushToStack
const input document.getElementByIdstackInputvalue;
if isNaNinput
stack.pushparseFloatinput;
else
stack.displayOutputInvalid input: Please enter a number";
document.getElementByIdstackInputvalue ; Clear the input box after push
function evaluate
const input document.getElementByIdstackInputvalue;
let result;
if includesinput
const operand stack.pop;
const operand stack.pop;
if operand null && operand null
switchinput
case :
result operand operand;
break;
case :
result operand operand;
break;
case :
result operand operand;
break;
case :
if operand
stack.displayOutputError: Division by zero";
return;
result operand operand;
break;
stack.pushresult;
else
stack.displayOutputError: Not enough operands";
else
stack.displayOutputInvalid operator: Please enter or ;
document.getElementByIdstackInputvalue ; Clear the input box after evaluation
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
