This function returns the highest and lowest number of all those entered, so I want to validate that the user does or does enter two numbers, but I can't get it
let arr = [-1, 5, 14, 0, 6];
const elevarNumeros = (arr = undefined) => {
if (arr === undefined) return alert("Debes ingresar los numeros");
if (!(arr instanceof Array)) return alert(`${arr} no es un número`);
// Puse el if que sigue para tratar de validar pero no funciona
if (length.arr < 1) return alert("Debes ingresar dos numeros o más");
for (let num of arr) {
if (typeof num !== "number") return alert(`${arr} no es un número`);
}
console.log(`El numero mas alto es el ${Math.max(...arr)} y el mas bajo ${Math.min(...arr)}`)
}
elevarNumeros(arr);
The error is in the third
if
one because you are accessing the size of the array incorrectly and it would be validated that it has more than 1 element.The complete code would be:
try this code
the length tag comes after your variable enter the code here
You already have the answer to your problem from As they comment it is an error in the Syntax . I wanted to leave you an addition regarding possible errors with different types of specific data that the user could insert. See.
@nashvent