Sum All Numbers in a Range

Tell us what’s happening:

Could anyone tell me what is wrong with my code?
I have traced my code via
The problem seems to occur on the for loop part.

Your code so far

function sumAll(arr) {
  var max = Math.max(...arr);
  var min = Math.min(...arr);
  var result = 0;
  for(; min <= max; min++ ){
     result+= min;
  return result;

sumAll([1, 4]);

Your browser information:

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

Link to the challenge:

You are missing the initial or start variable of your for loop, the exit condition of the loop is also wrong , in general I suggest you review how for loops are done in JavaScript

You don’t need a start condition (you don’t need any of the conditions, technically, just two semicolons is valid syntax, if confusing).

@lazerta this works fine, have you just tried refreshing the browser and running it again, I get no issues at all

1 Like

oh yes the expressions in the head of the for loop are optional in javaScript, I was confusing it with C, still, personally I’d rather have all 3 expressions in to avoid confusion.

1 Like

It did work!. Thanks.