-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
145 lines (142 loc) · 3.65 KB
/
script.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
140
141
142
143
144
145
const nat = document.querySelector(".result__text");
const txt = document.querySelector(".text");
const num1 = document.querySelector(".num_1");
const num2 = document.querySelector(".num_2");
const num3 = document.querySelector(".num_3");
const num4 = document.querySelector(".num_4");
const num5 = document.querySelector(".num_5");
const num6 = document.querySelector(".num_6");
const num7 = document.querySelector(".num_7");
const num8 = document.querySelector(".num_8");
const num9 = document.querySelector(".num_9");
const num0 = document.querySelector(".num_0");
const qosh = document.querySelector(".qosh");
const ayir = document.querySelector(".ayir");
const kopaytir = document.querySelector(".kopaytir");
const qoldiq = document.querySelector(".qoldiq");
const clear = document.querySelector(".clear");
const nuqta = document.querySelector(".nuqta");
const teng = document.querySelector(".teng");
const plus_minus = document.querySelector(".plus_minus");
const bol = document.querySelector(".bolish");
let check = true;
num0.addEventListener("click", () => {
nat.textContent += 0;
check = true;
});
num1.addEventListener("click", () => {
nat.textContent += 1;
check = true;
});
num2.addEventListener("click", () => {
nat.textContent += 2;
check = true;
});
num3.addEventListener("click", () => {
nat.textContent += 3;
check = true;
});
num4.addEventListener("click", () => {
nat.textContent += 4;
check = true;
});
num5.addEventListener("click", () => {
nat.textContent += 5;
check = true;
});
num6.addEventListener("click", () => {
nat.textContent += 6;
check = true;
});
num7.addEventListener("click", () => {
nat.textContent += 7;
check = true;
});
qosh.addEventListener("click", () => {
if (check) {
nat.textContent += " " + "+" + " ";
check = false;
}
});
num8.addEventListener("click", () => {
nat.textContent += 8;
check = true;
});
num9.addEventListener("click", () => {
nat.textContent += 9;
check = true;
});
bol.addEventListener("click", () => {
if (check) {
nat.textContent += " " + "/" + " ";
check = false;
}
});
kopaytir.addEventListener("click", () => {
if (check) {
nat.textContent += " " + "*" + " ";
check = false;
}
});
qoldiq.addEventListener("click", () => {
if (check) {
nat.textContent += " " + "%" + " ";
check = false;
}
});
ayir.addEventListener("click", () => {
if (check) {
nat.textContent += " " + "-" + " ";
check = false;
}
});
nuqta.addEventListener("click", () => {
if (check) {
nat.textContent += ".";
check = false;
}
});
clear.addEventListener("click", () => {
nat.textContent = "";
check = true;
});
teng.addEventListener("click", () => {
// nat.textContent = eval(nat.textContent);
let arr = nat.textContent.split(" ");
for (let i = 0; i < arr.length + 1; i++) {
if (arr[i] == "%") {
let sum = Number(arr[i - 1] / 100) * Number(arr[i + 1]);
arr.splice(i - 1, 3, sum);
i = 0;
}
}
for (let i = 0; i < arr.length; i++) {
if (arr[i] == "/") {
let sum = Number(arr[i - 1]) / Number(arr[i + 1]);
arr.splice(i - 1, 3, sum);
i = 0;
}
}
for (let i = 0; i < arr.length + 1; i++) {
if (arr[i] == "*") {
let sum = Number(arr[i - 1]) * Number(arr[i + 1]);
arr.splice(i - 1, 3, sum);
i = 0;
}
}
for (let i = 0; i < arr.length; i++) {
if (arr[i] == "+") {
let sum = Number(arr[i - 1]) + Number(arr[i + 1]);
arr.splice(i - 1, 3, sum);
i = 0;
}
}
for (let i = 0; i < arr.length; i++) {
if (arr[i] == "-") {
let sum = Number(arr[i - 1]) - Number(arr[i + 1]);
arr.splice(i - 1, 3, sum);
i = 0;
}
}
nat.textContent = arr.join("");
});