Tell us what’s happening:
Detailed in comments below but basically I can get two of the four test cases to pass by changing the comparison operator but not all four. I feel like the math adds up either way but I can’t understand why it won’t fully pass.
**Your code so far**
function sumAll(arr) {
let count = 0;
arr.sort((a, b) => a - b);
/*
//This lets the last two tests (5, 10 and 10, 5) but not the first two tests (1, 4 and 4, 1)
for(let i = 0; i < arr[1]; i++)
{
count += i;
}
*/
////This lets the first two tests (1, 4 and 4, 1) but not the last two tests (5, 10 and 10, 5)
for(let i = 0; i <= arr[1]; i++)
{
count += i;
}
//console.log(count);
return count;
}
sumAll([1, 4]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0
Challenge: Sum All Numbers in a Range
Link to the challenge: