-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaculate.js
45 lines (40 loc) · 987 Bytes
/
caculate.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
var result = "0";
var equation = "";
function numInput(elem) {
if (result == "0") {
result = elem.value;
} else {
result += elem.value;
}
console.log(result.length);
document.getElementById("screen").innerHTML = result;
}
function dotInput() {
result += ".";
document.getElementById("screen").innerHTML = result;
}
function operatorInput(elem) {
if (result != "0") {
equation += document.getElementById("screen").innerHTML;
if (elem.value == "x") {
equation += "*"
} else {
equation += elem.value;
}
result = "0";
}
}
function caculate() {
equation += result;
console.log(equation);
console.log(eval(equation));
document.getElementById("screen").innerHTML = eval(equation);
equation = "";
result = 0;
}
function erase() {
document.getElementById("screen").innerHTML = "0";
result = "0";
equation = "";
console.log('clear');
}