Works correctly in browser console, logs undefined. but won't pass FCC test

Tell us what’s happening:
What is wrong with this? It logs into my browser console "undefined just fine. But it won’t pass fcc test 4

Your code so far

function addTogether(){
  var x = arguments[0];
  if( typeof arguments[1] == 'number' && typeof arguments[0] == 'number' ){
    var y = arguments[1] + arguments[0];
    return y;
  }else{
    if( typeof arguments[0] == 'number' ){
      return function add(a){
        if( typeof a == 'number' ){
          return a+x;
        }else{
          console.log(undefined);
          return undefined;
        }
      };
    }
  }
}

addTogether(2)('3');

Your browser information:

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

Link to the challenge:
https://www.freecodecamp.org/challenges/arguments-optional

You are using addTogether(2)('3'), but the fourth test is: addTogether(2, "3"). Just walk through your code step for step:

  • if( typeof arguments[1] == 'number' && typeof arguments[0] == 'number' )
    This will return false, because the second argument is a string
  • So the else part is executed and if( typeof arguments[0] == 'number' ) is evaluated
    This will return true
  • Which results in returning:
      return function add(a){
        if( typeof a == 'number' ){
          return a+x;
        }else{
          console.log(undefined);
          return undefined;
        }
      };

Which is obviously not the same as “undefined”.