i am creating calculator when i click plus(+) operator i put the value in global variable which i get from input field and i do blank input field, but i have to take value from input which i enter second time and i have to keep another variable. that is i am trying to do but i don't understand how to do this.
JS Fiddle URL: http://jsfiddle.net/ravianexpert/9q6Xu/1
Please help me
var operation="";
var restValue="";
var lastValue="";
function operator(op){
if(op == '+'){
alert("Plus");
restValue = Number(document.getElementById("display").value);
document.getElementById("display").value="";
if(restValue == ""){
alert("Zero");
}else{
lastValue = Number(document.getElementById("display").value);
}
//document.getElementById("display").value=restValue + lastValue;
}
console.log("restValue : " + restValue);
console.log("lastValue : " + lastValue);
console.log("operation : " + operation);
//lastValue = restValue.charAt(restValue.length - 1);
//console.log(lastValue)
}
<div class="container">
<div id="lastCalculation"></div>
<input type="text" step="any" size="16" value="0" id="display" readonly />
<div class="keypad">
<span class="clear" onclick="reset()">C</span>
<span class="del" onclick="deleteValue()">Del</span>
<div class="clr"></div>
<span onclick="setNum(7)">7</span>
<span onclick="setNum(8)">8</span>
<span onclick="setNum(9)">9</span>
<span onclick="operator('/')">/</span>
<span onclick="setNum(4)">4</span>
<span onclick="setNum(5)">5</span>
<span onclick="setNum(6)">6</span>
<span onclick="operator('*')">*</span>
<span onclick="setNum(1)">1</span>
<span onclick="setNum(2)">2</span>
<span onclick="setNum(3)">3</span>
<span onclick="operator('-')">-</span>
<span onclick="setNum(0)">0</span>
<span onclick="setNum('.')">.</span>
<span class="isEqualTo" onclick="calculate()">=</span>
<span onclick="operator('+')">+</span>
<div class="clr"></div>
</div><!-- keypad -->
</div><!-- container -->