forked from marquez.juan/javascript-primeros-ejercicios
Compare commits
2 Commits
017e323993
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e82a87fa0a | ||
|
|
83911ea0e5 |
@@ -12,6 +12,8 @@ if (edad >= 18) {
|
||||
} else {
|
||||
console.log(`Hola, ${nombre}!, usted es menor de edad.`);
|
||||
}
|
||||
|
||||
|
||||
console.log("Ejercicio 3: Etapas de la vida");
|
||||
if (edad > 18) {
|
||||
console.log(`Hola, ${nombre}!, usted esta en su adultez.`);
|
||||
@@ -21,14 +23,18 @@ if (edad > 18) {
|
||||
console.log(`Hola, ${nombre}!, usted esta en su infancia.`);
|
||||
}
|
||||
|
||||
let maximo = 0;
|
||||
console.log("Ejercicio 4: Multiplos de 3 bucle while");
|
||||
while (maximo < 15) {
|
||||
console.log(maximo);
|
||||
maximo = maximo + 3;
|
||||
|
||||
const maximo = 15;
|
||||
let multiplos = 0
|
||||
|
||||
while (multiplos < maximo) {
|
||||
console.log(multiplos);
|
||||
multiplos = multiplos + 3;
|
||||
}
|
||||
|
||||
console.log("Ejercicio 5: Multiplos de 3 bucle for");
|
||||
for (let maximo2 = 0; maximo2 < 15; maximo2 = maximo2 + 3) {
|
||||
for (let maximo2 = 0; maximo2 < maximo; maximo2 = maximo2 + 3) {
|
||||
console.log(maximo2);
|
||||
}
|
||||
|
||||
@@ -36,4 +42,50 @@ console.log("Ejercicio 6: Array de frutas");
|
||||
const frutas = ["manzana", "banana", "mandarina"];
|
||||
for (const fruta of frutas) {
|
||||
console.log(fruta);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Ejercicio 7: Funcion saludar");
|
||||
|
||||
function presentarse(nombre, edad) {
|
||||
return `Hola, me llamo ${nombre} Tengo ${edad} años.`;
|
||||
}
|
||||
console.log(presentarse(nombre, edad));
|
||||
|
||||
|
||||
console.log("Ejercicio 8: Funcion arrays");
|
||||
const numeros = [ 1, 3, 8, 2, 18, 6 ];
|
||||
|
||||
function numeroMaximo(numeros) {
|
||||
let max = numeros[0];
|
||||
for (let i = 1; i < numeros.length; i++) {
|
||||
if (numeros[i] > max) {
|
||||
max = numeros[i];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
console.log(numeroMaximo(numeros));
|
||||
|
||||
|
||||
|
||||
function numeroMinimo(numeros) {
|
||||
let min = numeros[0];
|
||||
for (let i = 1; i > numeros.length; i++) {
|
||||
if (numeros[i] < min) {
|
||||
min = numeros[i];
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
console.log(numeroMinimo(numeros));
|
||||
|
||||
|
||||
|
||||
function promediar(numeros) {
|
||||
let suma = 0;
|
||||
for (let i = 0; i < numeros.length; i++) {
|
||||
suma = numeros[i] + suma;
|
||||
}
|
||||
return suma / numeros.length;
|
||||
}
|
||||
console.log(promediar(numeros));
|
||||
|
||||
Reference in New Issue
Block a user