-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (50 loc) · 1.48 KB
/
index.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
var memoryRegister = '';
let op = document.getElementById('op');
buttons = document.querySelectorAll('button');
let opValue = ' ';
for (item of buttons) {
item.addEventListener('click', (e) => {
buttonText = e.target.innerText;
if (buttonText == 'x') {
buttonText = '*';
opValue += buttonText;
op.value = opValue;
}
else if (buttonText == '√') {
opValue += Math.sqrt(opValue);
op.value = opValue;
}
else if (buttonText == '÷') {
buttonText = '/';
opValue += buttonText;
op.value = opValue;
}
else if (buttonText == '±') {
buttonText = '-';
opValue = opValue - (opValue * 2);;
op.value = opValue;
}
else if (buttonText == 'AC') {
opValue = "";
op.value = opValue;
}
else if (buttonText == '=') {
op.value = eval(opValue);
}
else if (buttonText == '⌫') {
opValue = opValue.slice(0, (opValue.length - 1));
op.value = opValue;
}
else if (buttonText == 'MS') {
memoryRegister = opValue;
}
else if (buttonText == 'MR') {
opValue = memoryRegister;
op.value = opValue;
}
else {
opValue += buttonText;
op.value = opValue;
}
});
}