-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15-1_desafios.js
More file actions
175 lines (144 loc) · 3.6 KB
/
15-1_desafios.js
File metadata and controls
175 lines (144 loc) · 3.6 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
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
// Desafios:
//1 ¿Cuál es su resultado?
let a = 3;
let b = new Number(3);
let c = 3;
console.log(typeof a);
console.log(typeof b);
console.log(typeof c);
console.log(a == b);
console.log(a === b);
console.log(b === c);
//2 ✅ Cambia el array original
function multiplyElements(array) {
console.log( typeof array );
console.log( array );
// Tu código aquí 👈
for (var i=0; i < array.length; i++) {
array[i] *= 2;
}
return array;
}
console.log( multiplyElements([2, 4, 5, 6, 8]) );
//3
switch (false) {
case false: console.log("Soy falso :( ")
case true: console.log("Soy verdadero!")
}
//4
// Tienes un array de objetos que representan datos de personas con los siguientes atributos:
// name: string
// lastName: string
// age: number
// Tu reto es retornar un array de strings con solo los nombres, para solucionarlo vas a encontrar una función llamada llamada getNames que recibe un parámetro de entrada:
// array: Un array de objetos.
let array = [
{
name: 'Nicolas',
lastName: 'Molina',
age: 28
},
{
name: 'Valentina',
lastName: 'Molina',
age: 19
},
{
name: 'Zulema',
lastName: 'Vicente',
age: 21
},
]
function getNames(array) {
// Tu código aquí 👈
return array.map(
function(array) {
let arrayName = array.name;
console.log(arrayName);
return arrayName;
}
)
}
console.log( getNames(array) );
// 5 Piramide de números
function piramideNumeros(numero){
var piramide = ""
while (numero<=10){
for (var i=1;i<=numero;i++){
piramide = piramide + i;
console.log(piramide);
}
break;
}
}
var numero = parseInt(prompt("Ingrese un numero:"))
piramideNumeros(numero)
function piramideRepetidos(tope) {
for (let i = 0; i < tope; i++) {
let piso = '';
for (let j = 0; j < i + 1; j++) {
piso = piso + i;
}
console.log(piso)
}
}
var tope = prompt("Ingrese un valor:")
piramideRepetidos(tope);
/* 10. Se pide realizar un script en el que el usuario introduce el número del mes (1 al 12) y devuelve si ese mes tiene 30 o 31 días.
28 febrero
30 abril junio septiembre noviembre
31 enero marzo mayo julio agosto octubre diciembre
Programador: Francisco Carusso
Fecha: 26/02/2023
Pais: Argentina
*/
function mes() {
let dias;
let fecha;
let pregunta;
const meses = [
'enero',
'febrero',
'marzo',
'abril',
'mayo',
'junio',
'julio',
'agosto',
'septiembre',
'octubre',
'noviembre',
'diciembre',
];
while (isNaN(fecha)) {
fecha = parseInt(prompt("Ingrese la fecha del mes del 1 al 12: "));
if (!isNaN(fecha)) {
while (fecha <= 0 || fecha >= 13) {
fecha = parseInt(prompt("Ingrese la fecha del mes del 1 al 12: "));
}
if (fecha > 0 && fecha <= 12) {
if (fecha == 2) {
dias = 28;
}
else if (fecha == 4 || fecha == 6 || fecha == 9 || fecha == 11) {
dias = 30;
}
else {
dias = 31;
}
console.log(`\nMes: ${fecha}, es ${meses[fecha - 1]}, tiene ${dias} días.\n`);
}
}
}
}
function ingresarMes() {
do {
mes();
console.log('----------------------------------');
pregunta = prompt('Ingresar otro mes? (si/no): ');
console.log('----------------------------------\n');
}
while (pregunta == 'si');
console.log('fin. 👍🏼\n');
}
ingresarMes();