diff --git a/ejercicios.js b/ejercicios.js index 72e9617..909d929 100644 --- a/ejercicios.js +++ b/ejercicios.js @@ -39,4 +39,53 @@ function presentarse(nombre, edad) { return `Me llamo ${nombre} y tengo ${edad} años`; } -console.log(presentarse("Lucho", 21)); \ No newline at end of file +console.log(presentarse("Lucho", 21)); + + + +const numeros = [1, 3, 8, 2, 18, 6] + +function valormaximo(valormax) { + let max = valormax[0]; + + for (const num of valormax) { + if (num > max) { + max = num; + } + } + + return max; +} + +console.log("Máximo:", valormaximo(numeros)); + + +function valorminimo(valormin) { + let min = valormin[0]; + + for (const num of valormin) { + if (num < min) { + min = num; + } + } + + return min; +} + +console.log("Mínimo:", valorminimo(numeros)); + + + +function valorpromedio(promedio) { + let suma = 0; + let contador = 0; + + for (const num of promedio) { + suma = (suma + num); + contador = (contador + 1); + } + + return suma / contador; +} + +console.log("Promedio:", valorpromedio(numeros)); \ No newline at end of file