-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
56 lines (52 loc) · 2.56 KB
/
main.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
// For changing theme
const left = () => document.documentElement.setAttribute("data-theme", "left");
const mid = () => document.documentElement.setAttribute("data-theme", "mid");
const right = () => document.documentElement.setAttribute("data-theme", "right");
// Taking values from the keys
const inputKey = document.form.screen;
// Inserting values to the display
const insertNum = (num) => {inputKey.value += num};
// Performimg operations using eval()
const equalTo = () => {
if((inputKey.value).indexOf("sin") > -1){
inputKey.value = Math.sin(inputKey.value.slice(3, inputKey.value.length));
}
else if((inputKey.value).indexOf("cos") > -1){
inputKey.value = Math.cos(inputKey.value.slice(3, inputKey.value.length));
}
else if((inputKey.value).indexOf("tan") > -1){
inputKey.value = Math.tan(inputKey.value.slice(3, inputKey.value.length));
}
else if((inputKey.value).indexOf("log") > -1){
inputKey.value = Math.log(inputKey.value.slice(3, inputKey.value.length));
}
else if((inputKey.value).indexOf("e") > -1){
inputKey.value = Math.exp(inputKey.value.slice(1, inputKey.value.length));
}
else if((inputKey.value).indexOf("^") > -1){
inputKey.value = Math.pow(inputKey.value.slice(0, (inputKey.value).indexOf("^")), inputKey.value.slice((inputKey.value).indexOf("^")+1), inputKey.value.length);
}
else if((inputKey.value).indexOf("⫪") > -1){
if((inputKey.value).indexOf("*")>-1){
inputKey.value = (inputKey.value.slice(0, (inputKey.value).indexOf("⫪")-1))*(Math.PI);
}else if(inputKey.value.slice(0, (inputKey.value).indexOf("⫪")) == 0){
inputKey.value = Math.PI;
}else{
inputKey.value = (inputKey.value.slice(0, (inputKey.value).indexOf("⫪")))*(Math.PI);
}
}
else if((inputKey.value).indexOf("²") > -1){
inputKey.value = Math.pow(inputKey.value.slice(0, (inputKey.value).indexOf("²")), 2);
}
else if((inputKey.value).indexOf("√") > -1){
inputKey.value = Math.sqrt(inputKey.value.slice(1, inputKey.value.length));
}
else if((inputKey.value).indexOf("∛") > -1){
inputKey.value = Math.cbrt(inputKey.value.slice(1, inputKey.value.length));
}
else{inputKey.value = eval(inputKey.value)}
};
// To remove one value at a time
const eraseNum = () => inputKey.value = inputKey.value.substring(0, inputKey.value.length-1);
// Reseting all previuos values
const clearAll = () => {inputKey.value = "0"; inputKey.value ="";}