-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
166 lines (164 loc) · 5.19 KB
/
index.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
var count_calc = 0;
function teste() {
alert("oi");
}
function recebe_console(id) {
var console = document.getElementById("console").value;
var buttonID = document.getElementById("button" + id).value;
var novo_console = (document.getElementById("console").value =
console + buttonID);
}
function btnlimpaconsole() {
var limpa = (document.getElementById("console").value = "");
}
function soma(id) {
var val_console = document.getElementById("console").value;
var limpa = (document.getElementById("console").value = "");
var div_Adc = document.getElementById("adcaq");
var n_txt_console = document.createElement("P");
n_txt_console.innerHTML =
'<input id="value_console' +
count_calc +
'" value="' +
val_console +
'" class="text" readonly/> <input type="button" class="text" id="consoleadd' +
count_calc +
'" value="' +
id +
'"/>';
div_Adc.appendChild(n_txt_console);
count_calc++;
}
function subtr(id) {
var val_console = document.getElementById("console").value;
var limpa = (document.getElementById("console").value = "");
var div_Adc = document.getElementById("adcaq");
var n_txt_console = document.createElement("P");
n_txt_console.innerHTML =
'<input id="value_console' +
count_calc +
'" value="' +
val_console +
'" class="text" readonly/> <input type="button" class="text" id="consoleadd' +
count_calc +
'" value="' +
id +
'"/>';
div_Adc.appendChild(n_txt_console);
count_calc++;
}
function mult(id) {
var val_console = document.getElementById("console").value;
var limpa = (document.getElementById("console").value = "");
var div_Adc = document.getElementById("adcaq");
var n_txt_console = document.createElement("P");
n_txt_console.innerHTML =
'<input id="value_console' +
count_calc +
'" value="' +
val_console +
'" class="text" readonly/> <input type="button" class="text" id="consoleadd' +
count_calc +
'" value="' +
id +
'"/>';
div_Adc.appendChild(n_txt_console);
count_calc++;
}
function div(id) {
var val_console = document.getElementById("console").value;
var limpa = (document.getElementById("console").value = "");
var div_Adc = document.getElementById("adcaq");
var n_txt_console = document.createElement("P");
n_txt_console.innerHTML =
'<input id="value_console' +
count_calc +
'" value="' +
val_console +
'" class="text" readonly/> <input type="button" class="text" id="consoleadd' +
count_calc +
'" value="' +
id +
'"/>';
div_Adc.appendChild(n_txt_console);
count_calc++;
}
function igual(id) {
var val_console = document.getElementById("console").value;
var div_Adc = document.getElementById("adcaq");
var n_txt_console = document.createElement("P");
n_txt_console.innerHTML =
'<input id="value_console' +
count_calc +
'" value="' +
val_console +
'" class="text" readonly/> <input type="button" class="text" id="consoleadd' +
count_calc +
'" value="' +
id +
'"/>';
div_Adc.appendChild(n_txt_console);
count_calc++;
setTimeout(() => {
result(id);
}, 500);
}
function result(id) {
var result = 0;
var count_i_menos = 0;
for (let i = 0; i < count_calc; i++) {
var console = document.getElementById("consoleadd" + i).value;
if (console == "+") {
var value_console = +document.getElementById("value_console" + i).value;
result += value_console;
} else if (console == "-") {
var value_console = +document.getElementById("value_console" + i).value;
result -= value_console;
} else if (console == "x") {
var value_console = +document.getElementById("value_console" + i).value;
result *= value_console;
} else if (console == "/") {
var consvalue_consoleole = +document.getElementById("value_console" + i)
.value;
result /= value_console;
} else {
count_i_menos = i - 1;
var console_i_menos = document.getElementById(
"consoleadd" + count_i_menos
).value;
if (console_i_menos == "+") {
var val_console_i_menos = +document.getElementById("console").value;
// alert(val_console_i_menos);
result += val_console_i_menos;
} else if (console_i_menos == "-") {
var val_console_i_menos = +document.getElementById("console").value;
result -= val_console_i_menos;
} else if (console_i_menos == "x") {
var val_console_i_menos = +document.getElementById("console").value;
result *= val_console_i_menos;
} else if (console_i_menos == "/") {
var val_console_i_menos = +document.getElementById("console").value;
result /= val_console_i_menos;
}
}
alert(result);
}
var val_console = (document.getElementById("console").value = result);
count_calc = 0;
}
function InsereConsole(num) {
document.form.txtViewCalc.value = document.form.txtViewCalc.value + num;
}
function Igual() {
var equal = document.form.txtViewCalc.value;
if (equal != "") {
document.form.txtViewCalc.value = eval(equal);
}
}
function ApagaUm() {
var apgUm = document.form.txtViewCalc.value;
document.form.txtViewCalc.value = apgUm.substr(1);
}
function ApagaTudo() {
document.form.txtViewCalc.value = "";
}