ES6 - Use the Rest Parameter with Function Parameters

Tell us what’s happening:
Describe your issue in detail here.

Not know what to do ?

Your code so far

const sum = (...n) => {
  const args = [x, y, z];
  let n = 0;
  for (let i = 0; i < args.length; i++) {
    total += args[i];
  }
  return total;
}

Your browser information:

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

Challenge: ES6 - Use the Rest Parameter with Function Parameters

Link to the challenge:

You are changing too much. You don’t need to change the return statement, that works just fine. You just need to modify the function so it can accept an unlimited amount of numbers.

  • You are not using the n parameter you declared.

  • You are redeclaring n which is a syntax error when using let.

  • x, y, z are all undefined as they are no long in the parameter list.

  • You removed the total declaration so you are assigning values to an undeclared variable.


...n is an array of all the arguments passed to the function. That is what you should be looping instead of the fixed args array that is in the starting code.

const logFriends = (...names) => {
  console.log(names);
  for (let name of names) {
    console.log(name);
  }
}

logFriends('Ross', 'Rachel', 'Monica', 'Joey', 'Chandler', 'Phoebe');

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.