Problem with Arguments Optional challenge

Create a function that sums two arguments together. If only one argument is provided, then return a function that expects one argument and returns the sum.

For example, addTogether(2, 3) should return 5, and addTogether(2) should return a function.
If either argument isn’t a valid number, return undefined.
Everything else passed but this one didn’t:
addTogether(5, undefined)`should return undefined.


My code:

function addTogether(a, b) {
  if (typeof a === "number" && typeof b === "number"){
    return a + b; 
  }
  if (typeof a === "number" && b === undefined){
    return function addB(b){
      if (typeof b === "number"){
        return a + b; 
      } else{
        return undefined; 
      }
    };
    } else{
      return undefined; 
    }



}

console.log(addTogether(2,3));

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

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