-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
150 lines (119 loc) · 2.99 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
var answered=false;
var Ans;
function display(a){
if(answered){
document.getElementById('screen').value = "";
answered=false;
}
document.getElementById('screen').value += a;
}
function bkspace () {
var a = document.getElementById('screen').value;
// Testing ground
// console.log(a);
var n = a.length;
// console.log(n);
// To print the last char '('
var last_char = a.charAt(n - 1);
// console.log(last_char);
// // This works for cos, sin, tan, log
// // var chars_trig = a.charAt(n - 4);
// // console.log(chars_trig);
var last_chars = a.slice(n-4, n);
// console.log(last_chars);
// // This works for arcsin, arccos, arctan
// // var chars_arc = a.charAt(n -7);
// // console.log(chars_arc);
var last_arc = a.slice(n-7, n);
// console.log(last_arc);
// // This works for sinh, cosh
// // var chars_hyp = a.charAt(n - 5);
// // console.log(chars_hyp);
var last_hyp = a.slice(n-5, n);
// console.log(last_hyp);
if ( (last_arc == 'arcsin(') || (last_arc == 'arccos(') || (last_arc == 'arctan(') ) {
// console.log(last_arc);
a = a.substr(0, n-7);
document.getElementById('screen').value = a;
// console.log(a);
} else if ( (last_hyp == 'sinh(') || (last_hyp == 'cosh(') ) {
// console.log(last_hyp);
a = a.substr(0, n-5);
document.getElementById('screen').value = a;
// console.log(a);
} else if ( (last_chars == 'cos(') || (last_chars == 'sin(') || (last_chars == 'tan(') || (last_chars == 'log(') ) {
// console.log(last_chars);
a = a.substr(0, n-4);
document.getElementById('screen').value = a;
// console.log(a);
} else{
a = a.substr(0, a.length - 1);
document.getElementById('screen').value = a;
}
}
function cls_screen () {
document.getElementById('screen').value = "";
document.getElementById('ans').value = "";
}
function ans (){
var ans = document.getElementById('screen').value;
// var ans2 = document.getElementById('hidden_screen').value;
if (ans === "") {
document.getElementById('ans').value = "0";
}
else {
// alert(ans);
Ans = eval(ans);
document.getElementById('ans').value = Ans;
}
answered=true;
}
function sin (a) {
a = Number(a);
return Math.sin(a * Math.PI / 180);
}
function arcsin(a){
a = Number();
return Math.asin(a * Math.PI / 180);
}
function sinh (a) {
a = Number(a);
return Math.sinh(a * Math.PI / 180);
}
function cos (a) {
a = Number(a);
return Math.cos(a * Math.PI / 180);
}
function arccos (a) {
a = Number(a);
return Math.acos(a * Math.PI / 180);
}
function cosh (a) {
a = Number(a);
return Math.cosh(a * Math.PI / 180);
}
function tan (a) {
a = Number(a);
// return (Math.sin(a * Math.PI / 180)) / (Math.cos(a * Math.PI / 180));
return Math.tan(a * Math.PI / 180);
}
function arctan (a) {
a = Number(a);
return Math.atan(a * Math.PI / 180);
}
function ln (a) {
a = Number(a);
return Math.log(a);
}
function log (a) {
a = Number(a);
return Math.log(a) / Math.log(10);
}
function sqrt (a) {
a = Number(a);
return Math.sqrt(a);
}
function cbrt (a) {
a = Number(a);
return Math.cbrt(a);
}