Sum All Numbers in a Range..3

Sum All Numbers in a Range..3
0

#1

Why is that not working? It does not work if the bigger number is 10 or above , why is that?

Your code so far


function sumAll(arr) {
  arr.sort();
  var newa =0;
  
  for(let i = arr[0];i<arr[1]+1;i++){
    newa+=i;
  }
 return newa;

  console.log(newa);
}

sumAll([5, 9]);

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/


#2

The arr.sort () function must have an argument function. By default, it orders by its alphabetic value instead of its numerical value.

I recommend this documentation:


#3

Not sure if you have solved it already but it looks like your for loop only counts up to the higher number but doesn’t include it

Edit: sorry looks like I was wrong, didn’t see the +1 at the end! You can sinlmplify it by using <= instead of +1