-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
55 lines (50 loc) · 1.7 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
let screen = document.getElementById('screen');
buttons = document.querySelectorAll('button');
let screenValue = '';
let solValue = '';
for (item of buttons) {
item.addEventListener('click', (e) => {
buttonText = e.target.innerText;
if (buttonText == 'X') {
buttonText = '*';
screenValue += buttonText;
solValue += ' X '
screen.value = solValue;
}
else if (buttonText == 'X^2') {
buttonText = '**2'; //give operator for calculation
screenValue += buttonText; //store value for calculation
solValue += '^2' //store value to display
screen.value = solValue; // to display value
}
else if (buttonText == 'pow') {
buttonText = '**';
screenValue += buttonText;
solValue += '^'
screen.value = solValue;
}
else if (buttonText == 'sqrt') {
screenValue =Math.sqrt(screenValue);
solValue += ' ^1/2'
screen.value = solValue;
}
else if (buttonText == 'AC') {
screenValue = "";
solValue = ''
screen.value = solValue;
}
else if (buttonText == '=') {
screen.value = eval(screenValue);
}
else if (buttonText == 'DEL') {
screenValue=screen.value.slice(0,-1);
solValue = screen.value.slice(0,-1);
screen.value = solValue;
}
else {
screenValue += buttonText;
solValue += buttonText;
screen.value = solValue;
}
})
}