Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is the 4th time i am asking this question so PLEASE only answer if you will

ID: 668374 • Letter: T

Question

This is the 4th time i am asking this question so PLEASE only answer if you will give me a working jsfiddle link, WORKING not something with errors PLEASE

Implement a Stack computer in Javascript (you will turn in a link to your program in JSFiddle). This is a simple computer that keeps a 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.

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.

Explanation / Answer

<html>
   <head>
       <script language = "Javascript">
           var a=prompt("Enter no");
           var b=prompt("Enter no");
           var c= prompt("Enter operation symbol");
           var a1=0, b1=0,c1=0;
           var stack=[]
       </script>
   </head>
   <body>
       <script language = "Javascript">
           a1=eval(a);
           b1=eval(b);
           stack.push(a1);
           stack.push(b1);
          
           if(c=="+")
           {
               c1=stack.pop()+stack.pop();
               stack.push(c1);
           }
           if(c=="-")
           {
               c1=stack.pop()-stack.pop();
               stack.push(c1);
           }
           if(c=="*")
           {
               c1=stack.pop()*stack.pop();
               stack.push(c1);
           }
           if(c=="/")
           {
               c1=stack.pop()/stack.pop();
               stack.push(c1);
           }
           document.write ("Result is"+c1);
       </script>
   </body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote