-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
121 lines (86 loc) · 2.28 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
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
var input = document.querySelector(".in");
var result = document.querySelector(".result");
var keys = document.querySelector(".keys");
var button = document.querySelector(".keys");
let bool = true;
var regNum = /\d+/g;
var regLet = /^([^0-9]*)$/;
function insert(target) {
var regNum = /\d+/g;
var regLet = /^([^0-9]*)$/;
if (target.innerHTML.length < 4) {
switch (true) {
case regNum.test(target.innerHTML):
if (bool) {
result.innerHTML = " ";
bool=false;
}
input.insertAdjacentHTML('beforeend', target.innerHTML);
break;
case regLet.test(target.innerHTML):
bool=false;
operationSwitch(target);
break;
case /1/:
console.log("zahlen");
break;
default:
}
}
}
function event() {
keys.addEventListener('click', function(e) {
insert(e.target);
}, false);
}
function operationSwitch(target) {
switch (target.innerHTML) {
case "C":
input.innerHTML = " ";
if (input.innerHTML = " ") {
result.innerHTML = " ";
console.log("baba");
}
break;
case "DEL":
if (input.innerHTML.substring(input.innerHTML.length - 1, input.innerHTML.length) == ".") {
document.querySelector(".point").disabled = false;
}
input.innerHTML = input.innerHTML.substring(0, input.innerHTML.length - 1);
if (input.innerHTML.length == 0) {
input.innerHTML = result.innerHTML;
result.innerHTML = ""
}
break;
case ".":
input.insertAdjacentHTML('beforeend', target.innerHTML);
target.disabled = false;
break;
case "=":
resultCalc();
break;
default:
input.insertAdjacentHTML('beforeend', target.innerHTML)
result.insertAdjacentHTML('beforeend', input.innerHTML)
input.innerHTML = "";
document.querySelector(".point").disabled = false;
document.querySelector(".resultButton").disabled=false;;
}
}
function resultCalc() {
result.insertAdjacentHTML('beforeend', input.innerHTML);
input.innerHTML = "";
var result2;
document.querySelector(".resultButton").disabled=true;
bool=true;
try {
result2 = eval(result.textContent + " ");
return result.innerHTML = result2;
} catch (e) {
result.innerHTML = "INPUT INVALID"
setTimeout(function() {
result.innerHTML = "";
}, 1000);
}
}
event();