diff options
Diffstat (limited to 'demos/declarative/calculator/calculator.js')
-rw-r--r-- | demos/declarative/calculator/calculator.js | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/demos/declarative/calculator/calculator.js b/demos/declarative/calculator/calculator.js index 774b232..cd6490a 100644 --- a/demos/declarative/calculator/calculator.js +++ b/demos/declarative/calculator/calculator.js @@ -5,9 +5,9 @@ var lastOp = ""; var timer = 0; function disabled(op) { - if (op == "." && CurNum.text.toString().search(/\./) != -1) { + if (op == "." && curNum.text.toString().search(/\./) != -1) { return true; - } else if (op == "Sqrt" && CurNum.text.toString().search(/-/) != -1) { + } else if (op == "Sqrt" && curNum.text.toString().search(/-/) != -1) { return true; } else { return false; @@ -20,12 +20,12 @@ function doOp(op) { } if (op.toString().length==1 && ((op >= "0" && op <= "9") || op==".") ) { - if (CurNum.text.toString().length >= 14) + if (curNum.text.toString().length >= 14) return; // No arbitrary length numbers if (lastOp.toString().length == 1 && ((lastOp >= "0" && lastOp <= "9") || lastOp==".") ) { - CurNum.text = CurNum.text + op.toString(); + curNum.text = curNum.text + op.toString(); } else { - CurNum.text = op; + curNum.text = op; } lastOp = op; return; @@ -33,55 +33,55 @@ function doOp(op) { lastOp = op; // Pending operations - if (CurrentOperation.text == "+") { - CurNum.text = Number(CurNum.text.valueOf()) + Number(curVal.valueOf()); - } else if (CurrentOperation.text == "-") { - CurNum.text = Number(curVal) - Number(CurNum.text.valueOf()); - } else if (CurrentOperation.text == "x") { - CurNum.text = Number(curVal) * Number(CurNum.text.valueOf()); - } else if (CurrentOperation.text == "/") { - CurNum.text = Number(Number(curVal) / Number(CurNum.text.valueOf())).toString(); - } else if (CurrentOperation.text == "=") { + if (currentOperation.text == "+") { + curNum.text = Number(curNum.text.valueOf()) + Number(curVal.valueOf()); + } else if (currentOperation.text == "-") { + curNum.text = Number(curVal) - Number(curNum.text.valueOf()); + } else if (currentOperation.text == "x") { + curNum.text = Number(curVal) * Number(curNum.text.valueOf()); + } else if (currentOperation.text == "/") { + curNum.text = Number(Number(curVal) / Number(curNum.text.valueOf())).toString(); + } else if (currentOperation.text == "=") { } if (op == "+" || op == "-" || op == "x" || op == "/") { - CurrentOperation.text = op; - curVal = CurNum.text.valueOf(); + currentOperation.text = op; + curVal = curNum.text.valueOf(); return; } curVal = 0; - CurrentOperation.text = ""; + currentOperation.text = ""; // Immediate operations if (op == "1/x") { // reciprocal - CurNum.text = (1 / CurNum.text.valueOf()).toString(); + curNum.text = (1 / curNum.text.valueOf()).toString(); } else if (op == "^2") { // squared - CurNum.text = (CurNum.text.valueOf() * CurNum.text.valueOf()).toString(); + curNum.text = (curNum.text.valueOf() * curNum.text.valueOf()).toString(); } else if (op == "Abs") { - CurNum.text = (Math.abs(CurNum.text.valueOf())).toString(); + curNum.text = (Math.abs(curNum.text.valueOf())).toString(); } else if (op == "Int") { - CurNum.text = (Math.floor(CurNum.text.valueOf())).toString(); + curNum.text = (Math.floor(curNum.text.valueOf())).toString(); } else if (op == "+/-") { // plus/minus - CurNum.text = (CurNum.text.valueOf() * -1).toString(); + curNum.text = (curNum.text.valueOf() * -1).toString(); } else if (op == "Sqrt") { // square root - CurNum.text = (Math.sqrt(CurNum.text.valueOf())).toString(); + curNum.text = (Math.sqrt(curNum.text.valueOf())).toString(); } else if (op == "MC") { // memory clear memory = 0; } else if (op == "M+") { // memory increment - memory += CurNum.text.valueOf(); + memory += curNum.text.valueOf(); } else if (op == "MR") { // memory recall - CurNum.text = memory.toString(); + curNum.text = memory.toString(); } else if (op == "MS") { // memory set - memory = CurNum.text.valueOf(); + memory = curNum.text.valueOf(); } else if (op == "Bksp") { - CurNum.text = CurNum.text.toString().slice(0, -1); + curNum.text = curNum.text.toString().slice(0, -1); } else if (op == "C") { - CurNum.text = "0"; + curNum.text = "0"; } else if (op == "AC") { curVal = 0; memory = 0; lastOp = ""; - CurNum.text ="0"; + curNum.text ="0"; } } |