The idea of this code is as follows:

is the second element or the first one bigger?

After deciding on such, add both elements to the global var sum and then decrease the bigger element by one and increase the smaller by one.

Do this until the difference between them is just one - since this is when you know all numbers between between the smaller and bigger elements of the array have been taken into account. Add all of these into sum as the loop goes through.

However, debug shows output is 5 when it should be 10 for [1,4] so that means 2 and 3 are not being counted into the summation. Is this an issue with the while loop I defined? Is the use of Math.ab fine?

**Your code so far**

```
function sumAll(arr) {
let first = arr[0];
let final = arr[1];
let sum = 0;
if (first>final) {
while ( (Math.abs(first-final)) >1) {
sum = sum + first + final;
first = first - 1;
final = final + 1;
}
} else if (final>first) {
while ( (Math.abs(first-final)) >1) {
sum = sum + first + final;
first = first + 1;
final = final - 1;
}
}
console.log(sum);
return sum;
}
sumAll([1, 4]);
```

**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36`

.

**Link to the challenge:**

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-numbers-in-a-range/