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));
}
I used console.log nothing came up, I will appreciate if I am corrected.
if the function is correct
function sumOfNumbers(arrayOfNumbers) { let arrayOfNumbers = [1, 2, 3, 4, 5, 6, 7] }the function returns the sum of the values of the array or vector
return (sumOfNumbers(sum));You have many mistakes in your code. Added comments in the code below to say what you did wrong and what you need to actually do.
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));