In this code I am creating 2 functions. In the first I declare the salaries and then I want to add the salaries in the second function. I don't know what I could have done wrong. The error that appears is: cannot read property 'length' of undefined" when I call the function sumSalaries();
function creaVectorSueldo(){
let sueldos = new Array(2);
for (var i = 0; i < sueldos.length; i++) {
let sueldosIngresados = parseInt(prompt('Ingrese sueldo: ',''));
sueldos[i] = sueldosIngresados;
}
return;
}
let recibeSueldos = creaVectorSueldo();
function sumaSueldos(){
let sumaSueldosTotal = 0;
for (let i = 0; i < recibeSueldos.length; i++) {
sumaSueldosTotal = sumaSueldosTotal + recibeSueldos[i];
}
document.write("La suma de los sueldos es: "+sumaSueldosTotal);
}
sumaSueldos();
The error occurs because in the function
creaVectorSueldo()
you need to return the variablesueldos
that contains what the user entered.