Rest Parameter with Function Parameters(lesson)

Hey guys I’m hoping someone can help me

const sum = (x, y, z) => {
  const args = [x, y, z];
  return args.reduce((a, b) => a + b, 0);
}

I’m not sure exactly what I’m supposed to do with this specific code

Welcome, joel.

Currently, the function sum can only take 3 arguments. The challenge is to modify it so that it can accept any number of arguments.

Take another look at how the example does it:

function howMany(...args) {
  return "You have passed " + args.length + " arguments.";
}
console.log(howMany(0, 1, 2)); // You canpass 3 arguments.
console.log(howMany(1, 3, 5, 6, 11)); // You can pass 5 arguments.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).


For future posts, if you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

1 Like

Thank you for the response and got it! :slight_smile: