RB_JSFiddle_A5
by Ryan Brown
HTML
<form id="formski">
<input type ="textbox" id="value" value="2" />
<br>
<input id ="buttonski" type ="button" value="enter first value, then second, then operator" onClick="Calculate();" />
<p id='output1'></p>
</form>
CSS
#formski
{
font-family: courier;
color: blue;
}
#buttonski
{
font-family: courier;
}
#value
{
width: 28em;
}
JavaScript
var Node = function(_content)
{
this.next = null;
this.last = null;
this.content = _content;
}
var Stack = function()
{
this.bottom = null;
this.top = null;
this.push = function(_content)
{
if (this.bottom == null)
{
this.bottom = new Node(_content);
this.top = this.bottom;
return this;
}
var addedNode = new Node(_content);
addedNode.last = this.top; // pointer to previous node
this.top.next = addedNode; // current top points to new
this.top = addedNode; // which becomes new top
return this;
}
this.pop = function()
{
if (this.bottom == null)
{
alert("The Stack is Empty");
return null;
}
// Case of one node
if (this.bottom == this.top)
{
var a = this.top.content;
this.bottom = null;
this.top = null;
return a;
}
// Now remove top Node
var a = this.top.content; // hold value for return
this.top = this.top.last;
this.top.next = null;
return a;
}
this.toString = function()
{
var str = "";
var node = this.bottom;
while (node != null)
{
str += node.content + ":";
node = node.next;
}
return str;
}
// operator functions \\
this.div = function()
{
var y = parseInt(stack.pop());
var x = parseInt(stack.pop());
var z = x/y
if(Number.isNaN(z) == false)
{
stack.push(z);
}
else
{
alert("Read the directions and try again.");
}
}
this.mul = function()
{
var y = parseInt(stack.pop());
var x = parseInt(stack.pop());
var z = x*y
if(Number.isNaN(z) == false)
{
stack.push(z);
...