I don't know why I am getting this error "TypeError: sumTwoAnd is not a function"

Tell us what’s happening:
Describe your issue in detail here.
Everything works perfectly not until I added this line to my code
if(typeof(arguments[0])!== “number” || typeof(arguments[1])!== “number”){

  return undefined;


   **Your code so far**

function addTogether(x, y) {
if(typeof(arguments[0])!== "number" || typeof(arguments[1])!== "number"){
     return undefined;
}else {
     if(arguments.length === 1){
               return function(y){
                  return x + y;
          }else {
          return x + y;
  var sumTwoAnd = addTogether(2);
console.log(addTogether(2, 5));

   **Your browser information:**

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

Challenge: Arguments Optional

Link to the challenge:

Well my first instinct would be to figure out what it is:

// undefined

When you call addTogether as a currying function with one parameter, you want to return a function.

When you call it like that, arguments[1] is not defined so typeof(arguments[1])!== "number" evaluates to true.

1 Like

As said, when you call the function with one argument then y is not a number, it is undefined.

You also have to check the argument for the return function as well. It too can be given an incorrect type, e.g. addTogether(2)([3]) should return undefined. As such, creating a utility function for checking the argument type might be useful.

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