-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
139 lines (117 loc) · 3.38 KB
/
scripts.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
let btn0 = document.getElementById("btn0");
let btn1 = document.getElementById("btn1");
let btn2 = document.getElementById("btn2");
let btn3 = document.getElementById("btn3");
let btn4 = document.getElementById("btn4");
let btn5 = document.getElementById("btn5");
let btn6 = document.getElementById("btn6");
let btn7 = document.getElementById("btn7");
let btn8 = document.getElementById("btn8");
let btn9 = document.getElementById("btn9");
let btnClr = document.getElementById("btnClr");
let btnEql = document.getElementById("btnEql");
let btnSum = document.getElementById("btnSum");
let btnSub = document.getElementById("btnSub");
let btnMul = document.getElementById("btnMul");
let btnDiv = document.getElementById("btnDiv");
function displaytext() {
let res = document.getElementById("res");
res.innerText += btn0.innerText;
}
function displaytext1() {
let res = document.getElementById("res");
res.innerText += btn1.innerText;
}
function displaytext2() {
let res = document.getElementById("res");
res.innerText += btn2.innerText;
}
function displaytext3() {
let res = document.getElementById("res");
res.innerText += btn3.innerText;
}
function displaytext4() {
let res = document.getElementById("res");
res.innerText += btn4.innerText;
}
function displaytext5() {
let res = document.getElementById("res");
res.innerText += btn5.innerText;
}
function displaytext6() {
let res = document.getElementById("res");
res.innerText += btn6.innerText;
}
function displaytext7() {
let res = document.getElementById("res");
res.innerText += btn7.innerText;
}
function displaytext8() {
let res = document.getElementById("res");
res.innerText += btn8.innerText;
}
function displaytext9() {
let res = document.getElementById("res");
res.innerText += btn9.innerText;
}
function btnClr1() {
let res = document.getElementById("res");
res.innerText = "";
}
function btnEql1() {
let res = document.getElementById("res");
console.log(res.innerText);
if(res.innerText.includes("+")){
let splitted = res.innerText.split("+");
console.log(splitted);
let sum = 0;
for(let i=0; i<splitted.length; i++){
sum += parseInt(splitted[i]);
}
console.log(sum);
res.innerText = sum;
} else if(res.innerText.includes("-")){
let splitted = res.innerText.split("-");
console.log(splitted);
let sum = splitted[0];
for(let i=1; i<splitted.length; i++){
sum -= parseInt(splitted[i]);
}
console.log(sum);
res.innerText = sum;
} else if(res.innerText.includes("*")){
let splitted = res.innerText.split("*");
console.log(splitted);
let sum = splitted[0];
for(let i=1; i<splitted.length; i++){
sum *= parseInt(splitted[i]);
}
console.log(sum);
res.innerText = sum;
} else if(res.innerText.includes("/")){
let splitted = res.innerText.split("/");
console.log(splitted);
let sum = splitted[0];
for(let i=1; i<splitted.length; i++){
sum /= parseInt(splitted[i]);
}
console.log(sum);
res.innerText = sum;
}
}
function btnSum1() {
let res = document.getElementById("res");
res.innerText += btnSum.innerText;
}
function btnSub1() {
let res = document.getElementById("res");
res.innerText += btnSub.innerText;
}
function btnMul1() {
let res = document.getElementById("res");
res.innerText += btnMul.innerText;
}
function btnDiv1() {
let res = document.getElementById("res");
res.innerText += btnDiv.innerText;
}