function sumOfNumbers(arrayOfNumbers) { let arrayOfNumbers = [1, 2, 3, 4, 5, 6, 7] const arrayLength = arrayOfNumbers.length; let sum = 0; for (i = 0; i <= arrayLength; i++) { sum = sum + arrayLength[i]; } /*console.log(sumOfNumbers(sum))*/ return (sumOfNumbers(sum)); }Utilicé console.log y no apareció nada, agradeceré que me corrijan.
si es correcta la función
function sumOfNumbers(arrayOfNumbers) {
let arrayOfNumbers = [1, 2, 3, 4, 5, 6, 7]
}la función retorna la suma de los valores del arreglo o vector
return (sumOfNumbers(sum));Tienes muchos errores en tu código. Se agregaron comentarios en el código a continuación para decir lo que hizo mal y lo que realmente necesita hacer.
function sumOfNumbers(arrayOfNumbers) { const arrayLength = arrayOfNumbers.length; let sum = 0; // you need to declare i so it is not a global // Indexes start at ZERO so the <= arrayLength would cause you to reference one past the length of the array for (let i = 0; i < arrayLength; i++) { // you are trying to read arrayOfNumbers... wrong, needs to be the array sum = sum + arrayOfNumbers[i]; } // return the sum return sum; } // define your array of numbers outside const myNumbers = [1, 2, 3, 4, 5, 6, 7]; // call the method passing in the array console.log(sumOfNumbers(myNumbers));