-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
147 lines (144 loc) · 3.88 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
146
147
let input = document.getElementById('searchinput');
let result = document.getElementById('symb16');
let del = document.getElementById('symb1');
let multi = document.getElementById('symb2');
let divd = document.getElementById('symb3');
let back = document.getElementById('symb4');
let one = document.getElementById('symb5');
let two = document.getElementById('symb6');
let thr = document.getElementById('symb7');
let plus = document.getElementById('symb8');
let fou = document.getElementById('symb9');
let fiv = document.getElementById('symb10');
let six = document.getElementById('symb11');
let min = document.getElementById('symb12');
let sev = document.getElementById('symb13');
let eig = document.getElementById('symb14');
let nin = document.getElementById('symb15');
let obra = document.getElementById('symb17');
let zer = document.getElementById('symb18');
let cbra = document.getElementById('symb19');
let poi = document.getElementById('symb20');
back.addEventListener('click', function () {
let CurrentValue = input.value;
input.value = CurrentValue.slice(0, -1);
});
obra.addEventListener('click', function () {
input.value += '(';
});
zer.addEventListener('click', function () {
input.value += '0';
});
cbra.addEventListener('click', function () {
input.value += ')';
});
poi.addEventListener('click', function () {
input.value += '.';
});
plus.addEventListener('click', function () {
let CurrentValue = input.value;
if (
CurrentValue.endsWith('+') ||
CurrentValue.endsWith('-') ||
CurrentValue.endsWith('/') ||
CurrentValue.endsWith('*')
) {
input.value = CurrentValue.slice(0, -1);
input.value += '+';
} else {
input.value += '+';
}
});
min.addEventListener('click', function () {
let CurrentValue = input.value;
if (
CurrentValue.endsWith('+') ||
CurrentValue.endsWith('-') ||
CurrentValue.endsWith('/') ||
CurrentValue.endsWith('*')
) {
input.value = CurrentValue.slice(0, -1);
input.value += '-';
} else {
input.value += '-';
}
});
divd.addEventListener('click', function () {
let CurrentValue = input.value;
if (
CurrentValue.endsWith('+') ||
CurrentValue.endsWith('-') ||
CurrentValue.endsWith('/') ||
CurrentValue.endsWith('*')
) {
input.value = CurrentValue.slice(0, -1);
input.value += '/';
} else {
input.value += '/';
}
});
multi.addEventListener('click', function () {
let CurrentValue = input.value;
if (
CurrentValue.endsWith('+') ||
CurrentValue.endsWith('-') ||
CurrentValue.endsWith('/') ||
CurrentValue.endsWith('*')
) {
input.value = CurrentValue.slice(0, -1);
input.value += '*';
} else {
input.value += '*';
}
});
one.addEventListener('click', function () {
input.value += 1;
});
two.addEventListener('click', function () {
input.value += 2;
});
thr.addEventListener('click', function () {
input.value += 3;
});
fou.addEventListener('click', function () {
input.value += 4;
});
fiv.addEventListener('click', function () {
input.value += 5;
});
six.addEventListener('click', function () {
input.value += 6;
});
sev.addEventListener('click', function () {
input.value += 7;
});
eig.addEventListener('click', function () {
input.value += 8;
});
nin.addEventListener('click', function () {
input.value += 9;
});
del.addEventListener('click', function () {
document.getElementById('searchinput').value = '';
});
result.addEventListener('click', function () {
cucu();
});
function clearDisplay() {
input.value = '';
}
const cucu = function () {
try {
let res = eval(input.value);
input.value = res;
} catch (error) {
data = 'Error';
setTimeout(clearDisplay, 1500);
input.value = 'ERROR';
}
};
input.addEventListener('keyup', function (e) {
if (e.keyCode == 13) {
cucu();
}
});