Arguments Optional : addTogether(2)(3) HELP!

Arguments Optional : addTogether(2)(3) HELP!


Hi All! I need some help with my code for “arguments optional” challenge. I keep getting “TypeError: addTogether(…) is not a function” error for case addTogether(2)(3); Where have I gone wrong???

function addTogether() {
 function sumTwoAnd(num){      // function to use if only one argument.  
    return 2+num;
  var temp = "";   // need a var               
  if (arguments.length == 2  && typeof arguments[0] === "number" && typeof arguments[1] === "number"){  // if there are two agruments and they are numbers then add them
     temp = arguments[0]+arguments[1];   
  else  if (arguments.length == 1 && typeof arguments[0] === "number"){  // if only one argument and it is a number then add it to 2
    temp = sumTwoAnd(arguments[0]);         
  else{                                    // all other cases are undefined
    temp = undefined;
  console.log("temp = "+temp);
  return temp;


When two sets of arguments are given, addTogether needs to return a function. The second set of arguments will then become the arguments of this returned function.

I’d like to also point out a logical error. You have the function sumTwoAnd which will always add 2 to the argument. This is incorrect. When two sets of arguments are given, the sum of those two arguments should be the result.


Thanks ArielLeslie, i guess I’m not understanding the challenge fully. Looks like I also need to read up on functions that return functions - a bit alien to me at the moment.