-
Notifications
You must be signed in to change notification settings - Fork 0
/
pro-calculation.js
91 lines (78 loc) · 2.83 KB
/
pro-calculation.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
function NumberHandler(e){
document.getElementById('result').value += e.currentTarget.value;
if(e.currentTarget.value === "+" || e.currentTarget.value === "-" || e.currentTarget.value === "*" || e.currentTarget.value === "\/"){
MultiCalculation();
oparator.push(e.currentTarget.value);
}
else if(e.currentTarget.value === "="){
EqualButtonPressing();
}
else
return;
}
function MultiCalculation(){
result = document.getElementById('result').value
if(firstNumber == null){
firstNumber = result.substring(0, result.length - 1);
}
oparator.push(firstNumber);
document.getElementById('result').value = null;
firstNumber = null;
}
function EqualButtonPressing(){
secondNumber = document.getElementById('result').value;
secondNumber = secondNumber.substring(0, secondNumber.length - 1);
oparator.push(secondNumber);
secondNumber = null;
clickBtn = oparator.toString();
clickBtn = clickBtn.replace(/[,]/g, "");
result = eval(clickBtn);
document.getElementById('result').value = null;
oparator = [];
alert(result);
}
function ShowingData(){
showEleman = oparator.toString();
showEleman = showEleman.replace(/[,]/g, "");
document.getElementById('conclud').innerHTML = showEleman;
}
function Composer(callback){
return function(){
callback(event);
ShowingData();
}
}
let btn1 = document.getElementById('btnNumber1');
let btn2 = document.getElementById('btnNumber2');
let btn3 = document.getElementById('btnNumber3');
let btn4 = document.getElementById('btnNumber4');
let btn5 = document.getElementById('btnNumber5');
let btn6 = document.getElementById('btnNumber6');
let btn7 = document.getElementById('btnNumber7');
let btn8 = document.getElementById('btnNumber8');
let btn9 = document.getElementById('btnNumber9');
let btn0 = document.getElementById('btnNumber0');
let btnsum = document.getElementById('btnSumption');
let btnmin = document.getElementById('btnMines');
let btnequl = document.getElementById('btnEqual');
let btnmulti = document.getElementById('btnMulti');
let btndivider = document.getElementById('btnDivider');
let firstNumber = null;
let secondNumber = 0;
let clickBtn = null;
let oparator = []
btn1.onclick = Composer(NumberHandler);
btn2.onclick = Composer(NumberHandler);
btn3.onclick = Composer(NumberHandler);
btn4.onclick = Composer(NumberHandler);
btn5.onclick = Composer(NumberHandler);
btn6.onclick = Composer(NumberHandler);
btn7.onclick = Composer(NumberHandler);
btn8.onclick = Composer(NumberHandler);
btn9.onclick = Composer(NumberHandler);
btn0.onclick = Composer(NumberHandler);
btnsum.onclick = Composer(NumberHandler);
btnmin.onclick = Composer(NumberHandler);
btnequl.onmousedown = Composer(NumberHandler);
btnmulti.onclick = Composer(NumberHandler);
btndivider.onclick = Composer(NumberHandler);