Arguments Optional

My function wont pass the with the input of addTogether(5)(7); im confused because when this is input it gives an error that addTogether(…) is not a function. So it doesnt seem like it would ever work with any function.


function addTogether(a,b) {
  


  if (typeof(a) != "number" || typeof(b) != "number"){
    return undefined;
  } return (a + b);
}

addTogether(5)(7);

I think that you are missing a few cases in your logic.

  • If only one argument is provided, then return a function that expects one argument and returns the sum.

  • If either argument isn’t a valid number, return undefined.

The trick here is that there are really more cases implied by these conditions

  • Only one argument, which is a number

  • Only one argument, which is not a number

  • Two arguments, both of which are numbers

  • Two arguments, at least one of which is not a number

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