Arguments Optional. What is wrong?

Tell us what’s happening:
Not passing the 4th test

addTogether(2, “3”) should return undefined.

And this line of code never gets excuted, not sure why.

if(typeof y !== "number") return undefined;

Your code so far


function addTogether(x, y) {
  if(typeof x !== "number") return undefined;
  if(arguments.length === 2)
    return x + y;
    
  return function(y) {
    if(typeof y !== "number") return undefined;
    return x + y;
  }
  return undefined;
}

addTogether(2,3);

Your browser information:

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

Link to the challenge:

For addTogether(2, “3”), your function returns “23”, because the first if statement evaluates to false, but the second if statement evaluates to true, so when the following is executed:

return x + y;

You are concatenating a number with a string, so it gets coerced into a string of “23”.

The reason the following line does not execute in the addTogether(2, “3”) case, is an earlier return statement was executed first.

if(typeof y !== "number") return undefined;