-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.js
37 lines (35 loc) · 1.26 KB
/
system.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
function addInScreen(string) {
var screen = document.getElementById("screen");
screen.value += string;
}
function returner(){
var screen = document.getElementById("screen");
string = screen.value;
string = string.split(' ');
var result = 0;
for (let index = 0; index < string.length; index++) {
if(index == 0){
result = parseFloat(string[0]);
} else if (string[index] == '+') {
result += parseFloat(string[index + 1]);
} else if (string[index] == '-') {
result -= parseFloat(string[index + 1]);
} else if (string[index] == '*') {
result = result * parseFloat(string[index + 1]);
} else if (string[index] == 'x') {
result = result * parseFloat(string[index + 1]);
} else if (string[index] == 'X') {
result = result * parseFloat(string[index + 1]);
} else if (string[index] == '/') {
result = result / parseFloat(string[index + 1]);
} else if (string[index] == '√') {
result = Math.sqrt(result);
}
}
string = result.toString();
screen.value = string.replace("NaN", "ERROR");;
}
function clearScreen(){
var screen = document.getElementById("screen");
screen.value = "";
}