Summing numbers in a range

Hi Everyone. I am trying to find the sum of numbers in a range. My code works for all examples like 3, 6 --> 18 and 5, 10 ---> 45 , however when I try to do 1,1, it should return 1 but it isnt. Anyone mind lending a hand? See code below

function sumRange(from, to) {
  var result = from;
  if(to > from) {
    while (to > from) {
      from ++;
      result += from;
    return result;
  } else if (from > to) {
    result = to;
    while (from > to ) {
      result += to;
    return result;


Thanks in advance!

When from and to are equal to each other, both of your if conditions are false.

The reason sumRange(1, 1) returns undefined, is because your first if statement checks if 1 > 1,
Since 1 is not greater than 1, it evaluates to false and then else if statement asks if 1 > 1 ylelding the same evaluation of false, so nothing happens again.

Even though there is no return statement at the end of your function, JavaScript returns undefined for you.

ahhhhh >=!! Thank you so much

thanks so much!!! appreciate the help