-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
142 lines (111 loc) · 4.03 KB
/
script.js
File metadata and controls
142 lines (111 loc) · 4.03 KB
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
let arreglo=[];
let n=3;
function agregarOpcion(){
let votaciones=document.querySelector('#contenidoOpciones');
let divOpcion=document.createElement('div');
divOpcion.setAttribute('class','entrada');
let labelOpcion=document.createElement('label');
labelOpcion.setAttribute('for','opcion'+n);
let spanOpcion=document.createElement('span');
spanOpcion.textContent='Opcion '+n+' (Votos): ';
let inputOpcion=document.createElement('input');
inputOpcion.setAttribute('type','number');
inputOpcion.setAttribute('min','0');
inputOpcion.setAttribute('max','100');
inputOpcion.setAttribute('id','opcion'+n);
labelOpcion.appendChild(spanOpcion);
labelOpcion.appendChild(inputOpcion);
divOpcion.appendChild(labelOpcion);
votaciones.appendChild(divOpcion);
console.log('n= '+n);
n=n+1;
}
function enviarVotos(){
arreglo=[];
for(let i=1; i<n; i++){
console.log(i);
arreglo.push(parseInt(document.querySelector('#opcion'+i).value));
}
document.getElementById('enviado').textContent='Votos enviados para obtener resultados'
}
function obtenerResultadosVotaciones(){
let VotosGanador;
votosGanador=arreglo.reduce( (mayor,elemento) => {
mayor=Math.max(mayor,elemento);
return mayor;
}
,0);
opcionGanadora=arreglo.indexOf(votosGanador)+1;
totalVotos=arreglo.reduce( (acumulado,elemento) => {
return acumulado+=elemento;
}
,0);
document.getElementById('resultado').textContent='Ganó la opción '+opcionGanadora+' con '+votosGanador+' votos'+' de los '+totalVotos+' realizados';
return arreglo;
}
// Calculadora basica Jeison
const operacion =[];
let suma = document.getElementById("suma");
let resta = document.getElementById("resta");
let multiplicacion = document.getElementById("multiplicacion");
let division = document.getElementById("division");
let r = document.getElementById("r");
suma.addEventListener("click", sumar);
resta.addEventListener("click", restar);
multiplicacion.addEventListener("click", multiplicar);
division.addEventListener("click", dividir);
function sumar() {
let input1 = parseFloat(document.getElementById("input1").value);
let input2 = parseFloat(document.getElementById("input2").value);
operacion.push(input1, input2);
let res = operacion.reduce(
(sum, item) => sum + item,
0
);
r.innerText = `La respuesta es: ${res}`;
}
function restar() {
let input1 = parseFloat(document.getElementById("input1").value);
let input2 = parseFloat(document.getElementById("input2").value);
operacion.push(input1, input2);
let res1 = operacion.reduce(
(rest, item) => rest - item,
);
r.innerText = `La respuesta es: ${res1}`;
}
function multiplicar() {
let input1 = parseFloat(document.getElementById("input1").value);
let input2 = parseFloat(document.getElementById("input2").value);
operacion.push(input1, input2);
let res2 = operacion.reduce(
(mult, item) => mult * item,
1
);
r.innerText = `La respuesta es: ${res2}`;
}
function dividir() {
let input1 = parseFloat(document.getElementById("input1").value);
let input2 = parseFloat(document.getElementById("input2").value);
operacion.push(input1, input2);
let res3 = operacion.reduce(
(div, item) => div / item,
);
r.innerText = `La respuesta es: ${res3}`;
}
// Sumadora de vectores
let operacion1 =[];
let suma1 = document.getElementById("suma1");
let rta = document.getElementById("r1");
suma1.addEventListener("click", sumar1);
function sumar1() {
let input8 = parseFloat(document.getElementById("input8").value);
let input9 = parseFloat(document.getElementById("input9").value);
let input10 = parseFloat(document.getElementById("input10").value);
let input11 = parseFloat(document.getElementById("input11").value);
operacion1.push(input8, input9,input10,input11);
let rta = operacion1.reduce(
(sum, item) => sum + item,
0
);
r1.innerText = `La respuesta es: ${rta}`;
}