Sum all Numbers in a Range - Spread/Rest Operator not working

Hi folks,

i wrote this code in Atom, and there it is working fine. I pasted it to fcc, and there i get a error called “Spread/Rest Operator” is only available in ES6 (‘use esversion:6’) for the two lines:

var min = Math.min(...arr);
var max = Math.max(...arr);

function sumAll(arr) {
  var min = Math.min(...arr);
  console.log(min);
  var max = Math.max(...arr);
  console.log(max);

  var arrNew = [];
  for ( i = min; i < max +1; i++) {
    arrNew.push(i);
    console.log(arrNew);
  }
  var sum = arrNew.reduce(function(a, b) {
  return  a + b;
}, 0);
 console.log(sum);
}

sumAll([10, 5]);

Can anybody help me out there please? Many thanks in advance.

eazy

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

1 Like

You are missing the return statement at the end of you function.

2 Likes

You should be able to submit code even if it contains ES6 syntax. It’s just the editor complaining about seeing ES6, but you should be fine.

Ahh…Maaaan… :disappointed:

Thanks.