# Sum all numbers challenge not passing

Hi, can someone help me with this algorithm pls ? it logs out the correct answers for the conditions in the challenge but when i return the output it does not pass any conditions . what is wrong in my program?
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-numbers-in-a-range

To enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The â€śpreformatted textâ€ť tool in the editor (`</>`) will also add backticks around text.

Note: Backticks are not single quotes.

1 Like

sure thanks.

``````function sumAll(arr) {
var lower = arr[0];
var upper = arr[1];
var sum = [];
if (lower < upper){
while (lower <= upper){
sum.push(lower++);
}
console.log(sum);
} else {
while (lower >= upper){
sum.push(lower--);
}
console.log(sum);
}
return x+y;
}
}

sumAll([1, 4]);

``````

The instructions state â€śReturn the sum of those two numbers plus the sum of all the numbers between them.â€ť Your function displays the sum to the browser console but does not return the value to the calling function.

When I use return the challenge fails . I am still not able to figure out what is wrong with my code . even though it logs out the correct answer to the console , it fails to return the same.
could you pls help?

``````function sumAll(arr) {
var lower = arr[0];
var upper = arr[1];
var sum = [];
if (lower < upper){
while (lower <= upper){
sum.push(lower++);
}
return sum;
} else {
while (lower >= upper){
sum.push(lower--);
}
return sum;
}