Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
Verify if this line of codes are correct
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.

about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

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));

about 4 years ago · Santiago Gelvez Report

0

about 4 years ago · Santiago Gelvez Report

0

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));

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!