Please whats wrong with my code here?

Tell us what’s happening:
Not sure what I did wrong here

  **Your code so far**

function sumAll(arr) {
let fullArr = [];
let sum = 0;
const reducer = (accumulator, currentValue) => accumulator + currentValue;
arr.sort(function(a,b) {
  return a - b
});
for (let i = arr[0]; i <= arr[i]; i++) {
  fullArr.push(i);
}
sum = fullArr.reduce(reducer);
return sum;
}


sumAll([1, 4]);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:89.0) Gecko/20100101 Firefox/89.0

Challenge: Sum All Numbers in a Range

Link to the challenge:

There is an error in the comparison. Try to track the value of i and to which value of arr it’s compared.

for (let i = arr[0]; i <= arr[i]; i++)
2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.