@@ -5,12 +5,23 @@ function obtenerMayor(x, y) {
5
5
// Devuelve el número más grande
6
6
// Si son iguales, devuelve cualquiera de los dos
7
7
// Tu código:
8
+ if ( x < y ) {
9
+ return ( y ) ;
10
+ }
11
+ else {
12
+ return ( x ) ;
13
+ }
8
14
}
9
15
10
16
function mayoriaDeEdad ( edad ) {
11
17
//Determinar si la persona según su edad puede ingresar a un evento.
12
18
//Si tiene 18 años ó más, devolver --> "Allowed"
13
19
//Si es menor, devolver --> "Not allowed"
20
+ if ( edad >= 18 ) {
21
+ return ( "Allowed" ) ;
22
+ } else {
23
+ return ( "Not allowed" ) ;
24
+ }
14
25
}
15
26
16
27
function conection ( status ) {
@@ -19,6 +30,15 @@ function conection(status) {
19
30
//Cuando el estado es igual a 2, el usuario está "Away"
20
31
//De lo contrario, presumimos que el usuario está "Offline"
21
32
//Devolver el estado de conexión de usuario en cada uno de los casos.
33
+ if ( status == 1 ) {
34
+ return ( "Online" )
35
+ }
36
+ else if ( status == 2 ) {
37
+ return ( "Away" ) ;
38
+ } else {
39
+ return ( "Offline" ) ;
40
+
41
+ }
22
42
}
23
43
24
44
function saludo ( idioma ) {
@@ -28,6 +48,18 @@ function saludo(idioma) {
28
48
// Si "idioma" es "ingles", devuelve "Hello!"
29
49
// Si "idioma" no es ninguno de los anteiores o es `undefined` devuelve "Hola!"
30
50
// Tu código:
51
+ if ( idioma == "aleman" ) {
52
+ return ( "Guten Tag!" )
53
+ }
54
+ else if ( idioma == "mandarin" ) {
55
+ return ( "Ni Hao!" )
56
+ }
57
+ else if ( idioma == "ingles" ) {
58
+ return ( "Hello!" )
59
+ }
60
+ else {
61
+ return ( "Hola!" )
62
+ }
31
63
}
32
64
33
65
function colors ( color ) {
@@ -38,18 +70,37 @@ function colors(color) {
38
70
//En caso que el color recibido sea "orange", devuleve --> "This is orange"
39
71
//Caso default: devuelve --> "Color not found"
40
72
//Usar el statement Switch.
73
+ if ( color == "blue" || color == "red" || color == "green" || color == "orange" ) {
74
+
75
+ return ( "This is " + color )
76
+ }
77
+ else {
78
+ return ( "Color not found" )
79
+ }
41
80
}
42
81
43
82
function esDiezOCinco ( numero ) {
44
83
// Devuelve "true" si "numero" es 10 o 5
45
84
// De lo contrario, devuelve "false"
46
85
// Tu código:
86
+ if ( numero == 10 || numero == 5 ) {
87
+ return ( true )
88
+ }
89
+ else {
90
+ return ( false )
91
+ }
47
92
}
48
93
49
94
function estaEnRango ( numero ) {
50
95
// Devuelve "true" si "numero" es menor que 50 y mayor que 20
51
96
// De lo contrario, devuelve "false"
52
97
// Tu código:
98
+ if ( numero < 50 && numero > 20 ) {
99
+ return ( true )
100
+ }
101
+ else {
102
+ return ( false )
103
+ }
53
104
}
54
105
55
106
function esEntero ( numero ) {
@@ -60,13 +111,37 @@ function esEntero(numero) {
60
111
// De lo contrario, devuelve "false"
61
112
// Pista: Puedes resolver esto usando `Math.floor`
62
113
// Tu código:
114
+ return ( Number . isInteger ( numero ) )
115
+
63
116
}
64
117
65
118
function fizzBuzz ( numero ) {
66
119
// Si "numero" es divisible entre 3, devuelve "fizz"
67
120
// Si "numero" es divisible entre 5, devuelve "buzz"
68
121
// Si "numero" es divisible entre 3 y 5 (ambos), devuelve "fizzbuzz"
69
122
// De lo contrario, devuelve el numero
123
+ f = numero ;
124
+ g = numero ;
125
+ n = 0 ;
126
+ l = 0 ;
127
+ while ( n < numero ) {
128
+ n = n + 3 ;
129
+ }
130
+ while ( l < numero ) {
131
+ l = l + 5 ;
132
+ }
133
+ if ( n == numero ) { f = "fizz" } else { f = "" }
134
+ if ( l == numero ) { g = "buzz" } else { g = "" }
135
+ if ( f === g ) {
136
+ f = null ;
137
+ g = null ;
138
+ f = numero
139
+
140
+ }
141
+
142
+ return ( f + g )
143
+
144
+
70
145
}
71
146
72
147
function operadoresLogicos ( num1 , num2 , num3 ) {
@@ -75,7 +150,23 @@ function operadoresLogicos(num1, num2, num3) {
75
150
//Si alguno de los tres números es negativo, retornar ---> "Hay negativos"
76
151
//Si num3 es más grande que num1 y num2, aumentar su valor en 1 y retornar el nuevo valor.
77
152
//0 no es ni positivo ni negativo. Si alguno de los argumentos es 0, retornar "Error".
78
- //Si no se cumplen ninguna de las condiciones anteriores, retornar false.
153
+ //Si no se cumplen ninguna de las condiciones anteriores, retornar false.
154
+
155
+ if ( num1 == 0 || num2 == 0 || num3 == 0 ) {
156
+ return ( "Error" )
157
+ }
158
+ else if ( num1 < 0 || num2 < 0 || num3 < 0 ) {
159
+ return ( "Hay negativos" )
160
+ }
161
+ else if ( num1 > num2 && num1 > num3 && num1 > 0 ) {
162
+ return ( "Número 1 es mayor y positivo" )
163
+ }
164
+ else if ( num3 > num1 && num3 > num2 ) {
165
+ num3 = num3 + 1 ;
166
+ return ( num3 )
167
+ } else {
168
+ return ( false )
169
+ }
79
170
}
80
171
81
172
function esPrimo ( numero ) {
@@ -84,32 +175,60 @@ function esPrimo(numero) {
84
175
// Pista: un número primo solo es divisible por sí mismo y por 1
85
176
// Pista 2: Puedes resolverlo usando un bucle `for`
86
177
// Nota: Los números 0 y 1 NO son considerados números primos
178
+ if ( numero < 2 ) { return ( false ) }
179
+ for ( let i = 2 ; i < numero ; i ++ ) {
180
+ n = numero / i ;
181
+ if ( Number . isInteger ( n ) ) {
182
+ return ( false )
183
+ }
184
+ }
185
+ return ( true )
87
186
}
88
187
89
188
function esVerdadero ( valor ) {
90
189
//Escribe una función que reciba un valor booleano y retorne “Soy verdadero”
91
190
//si su valor es true y “Soy falso” si su valor es false.
92
191
//Escribe tu código aquí
93
-
192
+ if ( valor === true ) {
193
+ return ( "Soy verdadero" )
194
+ } else if ( valor == false ) {
195
+ return ( "Soy falso" )
196
+ }
94
197
}
95
198
96
199
function tablaDelSeis ( ) {
97
200
//Escribe una función que muestre la tabla de multiplicar del 6 (del 0 al 60).
98
201
//La función devuelve un array con los resultados de la tabla de multiplicar del 6 en orden creciente.
99
- //Escribe tu código aquí
100
-
202
+ //Escribe tu código aquí
203
+ var t6 = [ ]
204
+ for ( let i = 0 ; i < 11 ; i ++ ) {
205
+ m = 6 * i ;
206
+ t6 . push ( m ) ;
207
+ }
208
+ return ( t6 )
101
209
}
102
210
103
211
function tieneTresDigitos ( numero ) {
104
212
//Leer un número entero y retornar true si tiene 3 dígitos. Caso contrario, retorna false.
105
213
//Escribe tu código aquí
106
-
214
+ if ( numero < 1000 && numero > 99 ) {
215
+ return ( true )
216
+ }
217
+ else {
218
+ return ( false )
219
+ }
107
220
}
108
221
109
222
function doWhile ( numero ) {
110
223
//Implementar una función tal que vaya aumentando el valor recibido en 5 hasta un límite de 8 veces
111
224
//Retornar el valor final.
112
225
//Usar el bucle do ... while.
226
+ h = 0 ;
227
+ while ( h < 8 ) {
228
+ numero = numero + 5 ;
229
+ h = h + 1
230
+ }
231
+ return ( numero )
113
232
}
114
233
115
234
@@ -131,5 +250,5 @@ module.exports = {
131
250
esVerdadero,
132
251
tablaDelSeis,
133
252
tieneTresDigitos,
134
- doWhile
135
- } ;
253
+ doWhile,
254
+ } ;
0 commit comments