Arguments Optional- Need Help

Tell us what’s happening:

What am i doing wrong here?

Your code so far


function addTogether(a, b) {
  if (a === parseInt(a) && b === parseInt(b)) {

    return a + b;
  }

  else if (b == undefined) {
    return function sumtwoAnd(c) {
      return a + c;
  }
    }

  sumtwoAnd(5);
}

addTogether(2,3);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional

Instead of returning another function when one of arguments is invalid, you should just return undefined.

You are returning functions even though arguments aren’t valid.

The typeof operator is very useful in this challenge. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof for more.

Here is what I could come up with.
function addTogether() {
var arg = […arguments]
var a = arguments[0];
var b = arguments[1];

if (arg.length === 2){
while (typeof a === ‘number’ && typeof b === ‘number’){

return a + b
}

}
else if (typeof a !== ‘number’){
return undefined
}
else

return function(b) {
  if(typeof b === 'number' && typeof a === 'number')
    return a + b;
};   

}