Help "Use the Rest Operator with Function Parameters"

Tell us what’s happening:
Hi! I tried a few things and nothing works. Here is the last one. I saw in the console that the result was good. I get an error message that says “The sum function uses the … spread operator on the args parameter.” I’m confused. It seems to me that it is the rest operator. Also, in the tests, it says that we should use the spread operator, when the title says it’s about the rest operator. So I am really not sure what to change.

Your code so far


const sum = (function() {
  "use strict";
  return function sum(...theArgs) {
    return theArgs.reduce((a, b) => a + b, 0);
  };
})();
console.log(sum(1, 2, 3)); // 6

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:63.0) Gecko/20100101 Firefox/63.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-the-rest-operator-with-function-parameters/

Your code is correct, but change the name of the parameter from theArgs to only args. FCC is checking for this name that’s why any other won’t work in the challenge.

1 Like

Alrighty! Thanks a lot!