Where am i doing error?

Tell us what’s happening:

I am getting the corresponding answers but whys its showing this error
The sum function uses the … spread operator on the args parameter.

Your code so far

const sum = (...args) => {
    return args.reduce((a,b) => a+b, 0);

Your browser information:

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

Link to the challenge:

The test is failing because you’re asked to modify the existing function, not to create your own ^^
It doesn’t mean your one is worse or something like that, simply the code has to pass some tests in order to be checked and if you change the original code this could mess something up with the test ^^

Since you have a correct function but is not matching with the test i’ll give you a correct one ( that will pass the tests) down below: i will suggest you to try to reset your code and modify the existent function though ^

const sum = (function() {
“use strict”;
return function sum(…args) {
// const args = [ x, y, z ];
return args.reduce((a, b) => a + b, 0);
console.log(sum(1, 2, 3)); // 6

1 Like

Thanks I got how to make it …

1 Like