-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
58 lines (54 loc) · 1.27 KB
/
main.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
function displayNumbers(num) {
input_screen.value += num.value;
}
function caluclatin() {
let arrayNumbers = [];
let ArrayOperators = [];
let numToCalculate = "";
let result = 0;
for (let i = 0; i < input_screen.value.length; i++) {
switch (input_screen.value[i]) {
case "+":
case "-":
case "*":
case "÷":
arrayNumbers.push(+numToCalculate);
numToCalculate = "";
ArrayOperators.push(input_screen.value[i]);
break;
default:
numToCalculate += input_screen.value[i];
break;
}
if (i == input_screen.value.length - 1) {
arrayNumbers.push(+numToCalculate);
}
}
result = arrayNumbers[0];
for (let i = 0; i < ArrayOperators.length; i++) {
switch (ArrayOperators[i]) {
case "+":
result += arrayNumbers[i + 1];
break;
case "-":
result -= arrayNumbers[i + 1];
break;
case "%":
result /= arrayNumbers[i + 1];
break;
case "*":
result *= arrayNumbers[i + 1];
break;
default:
break;
}
}
input_screen.value = result
}
function deleteAll() {
input_screen.value.toString();
input_screen.value=input_screen.value.slice(0,-1)
}
function clearAll() {
input_screen.value=""
}