forked from COPS-CSOC-2022/CSOC22-Week1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain11.js
98 lines (95 loc) · 3.06 KB
/
main11.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
92
93
94
95
96
97
98
let display = document.getElementById('display');
let buttons = Array.from(document.getElementsByClassName('button'));
buttons.map(button => {
button.addEventListener('click', (e) => {
switch (e.target.innerText) {
// Here we added break after end of case C because it was leaving C
// we stopped its execution after printing'' so it left default case
case 'C':
display.innerText = '';
break;
case '←':
display.innerText = display.innerText.slice(0, -1);
break;
// here eval is used to evaluate mathematical operations
case '=':
try {
display.innerText = eval(display.innerText);
break;
}
catch {
display.innerText = 'Error!';
break;
}
case'sin(Rad)':
{
var x = display.innerText;
display.innerText = Math.sin(x);
break;
}
case'cos(Rad)':
{
var x = display.innerText;
display.innerText = Math.cos(x);
break;
}
case'tan(Rad)':
{
var x = display.innerText;
display.innerText = Math.tan(x);
break;
}
case'sec(Rad)':
{
var x = display.innerText;
display.innerText = 1/Math.cos(x);
break;
}
case'cosec(Rad)':
{
var x = display.innerText;
display.innerText = 1/Math.sin(x);
break;
}
case'sin(-1)(rad)':
{
var x = display.innerText;
display.innerText = Math.asin(x);
break;
}
case'cos(-1)(rad)':
{
var x = display.innerText;
display.innerText = Math.acos(x);
break;
}
case'tan(-1)(rad)':
{
var x = display.innerText;
display.innerText = Math.atan(x)
break;
}
case'cot(Rad)':
{
var x = display.innerText;
x = x * Math.PI / 180;
display.innerText = 1/Math.tan(x);
break;
}
case'log':
{
var x = display.innerText;
display.innerText = Math.log(x)/Math.log(10);
break;
}
case'√':
{
var x = display.innerText;
display.innerText = Math.sqrt(x);
break;
}
default:
display.innerText += e.target.innerText;
}
});
});