-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaller-1.js
336 lines (256 loc) · 9.52 KB
/
taller-1.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// CALCULOS Y FORMULAS
// ===================
// Codigo del cuadrado
function perimetroCuadrado(lado) {
return lado * 4;
}
function areaCuadrado (lado) {
return lado * lado
}
// Codigo del rectangulo
function perimetroRectangulo(lado1, lado2) {
return lado1 * 2 + lado2 + 2;
}
function areaRectangulo (lado1, lado2) {
return lado1 * lado2;
}
// Codigo del triangulo
function perimetroTriangulo (ladoTriangulo1, ladoTriangulo2, base) {
return ladoTriangulo1 + ladoTriangulo2 + base;
}
function areaTriangulo (base, altura) {
return ((base * altura) / 2).toFixed(2);
}
function esIsosceles(ladoTriangulo1, ladoTriangulo2, base) {
if (ladoTriangulo1 == ladoTriangulo2 && ladoTriangulo1 != base) {
// formula de altura de un isosceles --> raiz(a^2 - b^2 / 4)
altura = Math.sqrt((ladoTriangulo1 ** 2) - (base ** 2) / 4 );
console.log('aca')
console.log(altura)
return altura.toFixed(2);
} else {
return false;
}
}
// Codigo del circulo
const PI = Math.PI;
function diametroCirculo (radio) {
return radio * 2;
}
function perimetroCirculo(radio) {
const diametro = diametroCirculo(radio);
return (diametro * PI).toFixed(2);
}
function areaCirculo(radio) {
return ((radio * radio) * PI).toFixed(2);
}
// UTILIDADES
// ===================
function cleanError (id) {
errors = document.getElementById(id).querySelectorAll('.error');
for (e of errors) {
e.innerHTML = '';
}
}
function closeOverlay() {
const overlay = document.getElementById('overlay');
overlay.style.display = 'none';
}
// LLAMADAS
// ==========
// Cuadrado
function checkInputsSquare(l1) {
if (Number.isNaN(l1) || l1 <= 0) {
e = document.getElementById('errorCL1');
e.innerHTML = 'Ingrese un valor válido para el Lado A';
return false;
}
return true;
}
function renderResultSquare(r, calc) {
const overlay = document.getElementById('overlay');
overlay.style.display = 'grid';
const unit = calc == 'Area' ? 'cm<span>2</span>' : 'cm';
const resultIMG = document.getElementById('resultIMG');
const resultH2 = document.getElementById('resultH2');
const resultH4 = document.getElementById('resultH4');
resultIMG.src = 'assets/img/square.png';
resultH2.innerHTML = 'Cuadrados';
resultH4.innerHTML = `El <strong>${calc}</strong> del <strong>cuadrado</strong> es: <strong class="unit"> ${r} ${unit}</strong>`;
}
function calcularPerimetroCuadrado() {
cleanError('cuadrados');
const lado = parseInt(document.getElementById('inputCuadrado').value);
if(checkInputsSquare(lado)) {
const result = perimetroCuadrado(lado);
renderResultSquare(result, 'Perimetro');
}
}
function calcularAreaCuadrado() {
cleanError('cuadrados');
const lado = parseInt(document.getElementById('inputCuadrado').value);
if(checkInputsSquare(lado)) {
const result = areaCuadrado(lado);
renderResultSquare(result, 'Area');
}
}
// Rectangulo
function checkInputsCube(l1, l2) {
if (Number.isNaN(l1) || l1 <= 0) {
e = document.getElementById('errorRL1');
e.innerHTML = 'Ingrese un valor válido para el Lado A';
return false;
}
if (Number.isNaN(l2) || l2 <= 0) {
e = document.getElementById('errorRL2');
e.innerHTML = 'Ingrese un valor válido para el Lado B';
return false;
}
return true;
}
function renderResultCube(r, calc) {
const overlay = document.getElementById('overlay');
overlay.style.display = 'grid';
const unit = calc == 'Area' ? 'cm<span>2</span>' : 'cm';
const resultIMG = document.getElementById('resultIMG');
const resultH2 = document.getElementById('resultH2');
const resultH4 = document.getElementById('resultH4');
resultIMG.src = 'assets/img/cube.png';
resultH2.innerHTML = 'Rectangulos';
resultH4.innerHTML = `El <strong>${calc}</strong> del <strong>rectangulo</strong> es: <strong class="unit"> ${r} ${unit}</strong>`;
}
function calcularPerimetroRectangulo() {
cleanError('rectangulos');
const lado1 = parseInt(document.getElementById('inputRectangulo1').value);
const lado2 = parseInt(document.getElementById('inputRectangulo2').value);
if(checkInputsCube(lado1, lado2)) {
const result = perimetroRectangulo(lado1, lado2);
renderResultCube(result, 'Perimetro');
}
}
function calcularAreaRectangulo() {
cleanError('rectangulos');
const lado1 = parseInt(document.getElementById('inputRectangulo1').value);
const lado2 = parseInt(document.getElementById('inputRectangulo2').value);
if(checkInputsCube(lado1, lado2)) {
const result = areaRectangulo(lado1, lado2);
renderResultCube(result, 'Area');
}
}
// Circulo
function checkInputsCircle(l1) {
if (Number.isNaN(l1) || l1 <= 0) {
e = document.getElementById('errorCirculo');
e.innerHTML = 'Ingrese un valor válido para el Lado A';
return false;
}
return true;
}
function renderResultCircle(r, calc) {
const overlay = document.getElementById('overlay');
overlay.style.display = 'grid';
const unit = calc == 'Area' ? 'cm<span>2</span>' : 'cm';
const resultIMG = document.getElementById('resultIMG');
const resultH2 = document.getElementById('resultH2');
const resultH4 = document.getElementById('resultH4');
resultIMG.src = 'assets/img/circle.png';
resultH2.innerHTML = 'Circulos';
resultH4.innerHTML = `El <strong>${calc}</strong> del <strong>circulo</strong> es: <strong class="unit"> ${r} ${unit}</strong>`;
}
function calcularPerimetroCirculo() {
cleanError('circulos');
const radio = parseInt(document.getElementById('inputCirculo').value);
if(checkInputsCircle(radio)){
const result = perimetroCirculo(radio);
renderResultCircle(result, 'Perimetro');
}
}
function calcularAreaCirculo() {
cleanError('circulos');
const radio = parseInt(document.getElementById('inputCirculo').value);
if(checkInputsCircle(radio)){
const result = areaCirculo(radio);
renderResultCircle(result, 'Area');
}
}
function calcularDiametroCirculo() {
cleanError('circulos');
const radio = parseInt(document.getElementById('inputCirculo').value);
if(checkInputsCircle(radio)){
const result = diametroCirculo(radio);
renderResultCircle(result, 'Diametro');
}
}
// Triangulo
function calcularAreaTriangulo() {
cleanError('triangulos');
const lado1 = false;
const lado2 = false;
const base = parseInt(document.getElementById('inputBase').value);
const altura = parseInt(document.getElementById('inputAltura').value);
console.log('aca1')
console.log(lado1)
console.log(lado2)
console.log(base)
console.log(altura)
if (checkInputsTriangulo(lado1, lado2, base, altura)) {
const result = areaTriangulo(base, altura);
renderResultTriangles(result, 'Area');
}
}
function calcularPerimetroTriangulo() {
cleanError('triangulos');
const lado1 = parseInt(document.getElementById('inputTriangulo1').value);
const lado2 = parseInt(document.getElementById('inputTriangulo2').value);
const base = parseInt(document.getElementById('inputBase').value);
const altura = false;
if (checkInputsTriangulo(lado1, lado2, base, altura)) {
const result = perimetroTriangulo(lado1, lado2, base);
renderResultTriangles(result, 'Perimetro');
}
}
function checkInputsTriangulo (l1, l2, b, h) {
if (h == false) {
if (Number.isNaN(l1) || l1 <= 0) {
e = document.getElementById('errorT1');
e.innerHTML = 'Ingrese un valor válido para el Lado A';
return false;
}
if (Number.isNaN(l2) || l2 <= 0) {
e = document.getElementById('errorT2');
e.innerHTML = 'Ingrese un valor válido para el Lado B';
return false;
}
if (Number.isNaN(b) || b <= 0) {
e = document.getElementById('errorTBase');
e.innerHTML = 'Ingrese un valor válido para la Base';
return false;
}
} else {
// Area
if (Number.isNaN(b) || b <= 0) {
console.log(32)
e = document.getElementById('errorTBase');
e.innerHTML = 'Ingrese un valor válido para la Base';
return false;
}
console.log(h);
if (Number.isNaN(h) || h <= 0) {
e = document.getElementById('errorTAltura');
e.innerHTML = 'Ingrese un valor válido para la Altura';
return false;
}
}
return true;
}
function renderResultTriangles(r, calc) {
const overlay = document.getElementById('overlay');
overlay.style.display = 'grid';
const unit = calc == 'Area' ? 'cm<span>2</span>' : 'cm';
const resultIMG = document.getElementById('resultIMG');
const resultH2 = document.getElementById('resultH2');
const resultH4 = document.getElementById('resultH4');
resultIMG.src = 'assets/img/triangle.png';
resultH2.innerHTML = 'Triangulos';
resultH4.innerHTML = `El <strong>${calc}</strong> del <strong>triangulo</strong> es: <strong class="unit"> ${r} ${unit}</strong>`;
}