-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (50 loc) · 998 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var num="";var n="";var input="+"; var lastinput="+";
var result=0; var store=0;
document.querySelector("#displaypanel").addEventListener("click",function() {
document.querySelector("#displaypanel").innerHTML = "0";
num=""; input="+"; lastinput="+";
result=0; store=0;n="";
})
function build(a)
{
n=n+a;
num=num+a;
document.getElementById("displaypanel").innerHTML=n;
}
function operator(op)
{
lastinput=input;
input=op;
//document.getElementById("displaypanel").innerHTML=input;
if(input=="=")
{
calc(lastinput);
document.getElementById("displaypanel").innerHTML=store;
n=store;
}
else
{
calc(lastinput);
}
}
function calc(lastinput)
{
result=store;
if(lastinput=="+")
{
store=result+parseInt(num);
}
else if(lastinput=="-")
{
store=result-parseInt(num);
}
else if(lastinput=="*")
{
store=result*parseInt(num);
}
else if(lastinput == "/")
{
store=result/parseInt(num);
}
num="";
}