Sum all numbers in a range help!


I have written code that works in a real sense (when loaded into VS Code and run through an actual webpage) and also when run through a JavaScript visualizer (, but it fails the FCC tests.

function sumAll(arr) {
    let smaller, greater, totalSum;
    smaller = arr[0] < arr[1] ? arr[0] : arr[1];
    greater = arr[0] > arr[1] ? arr[0] : arr[1];
    totalSum = 0;
    for (smaller; smaller <= greater; smaller++) {
        totalSum += smaller;
    return totalSum;

To try and figure out what’s going on, I’ve even run typeof on totalSum in my browser (produces “number”), run console.log at every step of the function, and I’m starting to suspect something is going on behind the scenes of the FCC compiler. The code above was copy/pasted from my VS Code window, which as I previously stated is working fine.


In the future, please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.

The easiest way to create a topic for help with your own solution is to click the Ask for Help button located on each challenge. This will automatically import your code in a readable format and pull in the challenge url while still allowing you to ask any question about the challenge or your code.

Thank you.

what do the failing tests say? can you provide the challenge link?

Thanks! I’ll make a new topic next time.

here’s a link to the challenge.

The errors are that I fail every test.

// running tests

sumAll([1, 4])

should return a number.

sumAll([1, 4])

should return 10.

sumAll([4, 1])

should return 10.

sumAll([5, 10])

should return 45.

sumAll([10, 5])

should return 45. // tests completed // console output

it may be related to this:

That worked, thank you for the quick response!