Having errors with "Sum All Numbers in a Range" exercise

Having errors with "Sum All Numbers in a Range" exercise
0

#1

i have been trying to solve the exercise on sum all numbers in a range and i am facing some issues.
This is my code so far. it returns the right value but does not validate the exercise.

I like some help on how to solve this problem

var sumArr = [];
function sumAll(arr) {
   var maxVal = Math.max(arr[0], arr[1]);
   var minVal = Math.min(arr[0], arr[1]);
 
  while(minVal <= maxVal){
  sumArr.push(minVal++);
  }
   var sumTotal = sumArr.reduce(function(sum, value){
     return (sum + value);
     
   }, 0);
  return (sumTotal);
}

sumAll([10, 5]);


Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36.

Link to the challenge:


#2

Try moving the

var sumArr = [];

inside the function. Declaring it globally will not work with the FCC tests, because it would not get reset to a blank array as the tests are ran consecutively.


#3

Thank you. it worked