What's wrong with this summing function?

The challenge is to make a summing function that sums the two values in the array input, and every other integer in between.
The console says that there’s a potential infinite loop on line 4. But since I’ve put the if condition, shouldn’t that take care of the issue? Or is there something else wrong?


function sumAll(arr) {
let sum = arr[0] + arr[1];
if(arr[0] < arr[1]){
  for(let i = arr[0] + 1; i++; i<= arr[1] -1){
    sum = sum + i
  } 
} else {
  for(let i = arr[1] + 1; i++; i<= arr[0] -1){
    sum = sum + i
}

}
return sum
}
sumAll([1, 4])

Challenge: Sum All Numbers in a Range

Link to the challenge:

I think the issue may be the order in which you set out your for loop

States that it should be like so:

for(let i = arr[0] + 1;  i <= arr[1] -1; i++){
    sum = sum + i
  }

so the program may be getting confused by this misplacement of syntax

1 Like

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