-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
91 lines (75 loc) · 2.12 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
class Arithematic {
sum(x, y) {
return x + y;
}
mul(x, y) {
return x * y;
}
sub(x, y) {
return x - y;
}
div(x, y) {
return x / y;
}
mod(x, y) {
return x % y;
}
}
var modulus = document.querySelector('#mod');
var del = document.querySelector('#delete');
var clear = document.querySelector('#clear');
var sq = document.querySelector('#sq');
let sign = document.querySelectorAll('.sign')
let nums = document.querySelectorAll('.btn > .num')
let inputDisplay = document.getElementById('content-display')
var value1;
var value2;
var count = 0;
var showValue = document.querySelector(".show-value > p");
let operation = new Arithematic();
sign.forEach(elem => {
elem.addEventListener('click', () => {
if(count == 0) {
value1 = +inputDisplay.value;
count++;
showValue.innerHTML = inputDisplay.value + elem.innerHTML;
inputDisplay.value = null;
}
else {
value2 = +inputDisplay.value;
switch(elem.innerHTML) {
case '+':
inputDisplay.value = operation.sum(value1, value2);
break;
case '-':
inputDisplay.value = operation.sub(value1, value2);
break;
case 'x':
inputDisplay.value = operation.mul(value1, value2);
break;
case '÷':
inputDisplay.value = operation.sum(value1, value2);
break;
case '%':
inputDisplay.value = operation.mod(value1, value2);
break;
}
count = 0;
}
});
});
let closeCalc = document.querySelector('#close-div');
closeCalc.addEventListener('click', () => {
document.body.remove();
})
nums.forEach(elem => {
elem.addEventListener('click', () => {
inputDisplay.value += elem.innerHTML;
});
});
clear.addEventListener('click', () => {
inputDisplay.value = null;
value1 = null;
value2 = null;
showValue.innerHTML = '';
})