Build an Optional Arguments Sum Function - Build an Optional Arguments Sum Function

Tell us what’s happening:

I’m having trouble passing tests 8 & 9 - my inner function is adding the second number twice when addTogether is called with two numbers like (5)(7). Any input would be great!

Your code so far

function addTogether() {
  if (arguments.length === 2 && typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
    return arguments[0] + arguments[1];

  } else if (arguments.length === 1 && typeof arguments[0] === 'number') {
    return function sumThis(num) {
      return arguments[0] + num;
    }
  } else {
    return undefined;
  }
}

console.log(addTogether(5)(7));

Your browser information:

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

Challenge Information:

Build an Optional Arguments Sum Function - Build an Optional Arguments Sum Function

Have you tried to check what values have variables used in the inner sumThis function?

1 Like

Have you tried using a rest parameter?

Rest parameters - JavaScript | MDN

And are you checking whether num is a number?

1 Like

Got it! Thank you for the help!