Arguments Optional: Code works on Atom, but not on FCC

Arguments Optional: Code works on Atom, but not on FCC
0

#1

when I run this code on Atom, I get the correct answers in all cases. When I run it on FCC, the second test fails: AddTogether(2) (3).

Can you help?
thanks.


function addTogether() {
  var args=Array.prototype.slice.call(arguments);
  //console.log("args length=", args.length);
  //console.log(args[0]);
  if (args.length>2) {
    return undefined;
  }
  for (i=0;i<args.length;i++) {
    //console.log("for loop");
    if (typeof args[i] == "string") {
      //console.log("here");
      return undefined;
    } else {
      //return console.log( "didn't work",(args[i] != args[i]));
    }
  }
  if (typeof args[0]=="string") {
  //  console.log("Single argument is not a number");
    return undefined;
  }
  if (args.length==2) {
    //alert(args);
    //console.log(args[0]+args[1]);
    return args[0] + args[1];
  } else {
    console.log("right place");
    return function(y) {
      var sumTwoAnd= args[0]+y;
      console.log(sumTwoAnd);
      //console.log(sumTwoAnd);
    };
  }

//  return false;
}

addTogether(2) (3);



#2

I think you have a missing return statement. You weren’t returning sumTwoAnd (you were simply printing it to the console).


#3

thanks. that was certainly part of it. also, I did not have an adequate check for the second parameter as [3] was not coming back as undefined.

thanks again.