Sum all numbers in a range - why doesn't this work? SOLVED

Never mind. The code is correct, I had to refresh my browser to make it work.

We’ll pass you an array of two numbers. Return the sum of those two numbers and all numbers between them.

The lowest number will not always come first.

This is my solution and it works in codepen, but it doesn’t get accepted here at FCC. What am I doing wrong?

function sumAll(arr) {
var lowest = Math.min.apply(null, arr);
var highest = Math.max.apply(null, arr);
var diff = highest - lowest;
var total = lowest;
for (var i = 1; i < diff+1; i++) {

total += lowest + i;


return total;

sumAll([1, 4]);

When I paste your code into FCC it passes all the tests. Try resetting your code and pasting it in again.

1 Like

I just found it out myself, thank you anyway. :+1:.