Arguments Optional problem

Arguments Optional problem
0.0 0

#1

Tell us what’s happening:
wherem m getting wrong? please help

Your code so far

function addTogether() {
  function sumTwoAnd(c){
    return c+arguments[0];
  }
  
  if(typeof arguments[0]=="number" && typeof(arguments[1])=="number")
  return arguments[0]+arguments[1];
  else if(arguments.length==1 && typeof arguments[0]=="number"){
    b=arguments[1];
    return sumTwoAnd(b);
  }
  else return undefined;
}

addTogether(2)(3);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:


Record Collection problem
#2

Your function call syntax is wrong.

Try: addTogether(2,3);


#3

A few things.

else if(arguments.length==1 && typeof arguments[0]=="number"){
    b=arguments[1];
    return sumTwoAnd(b);
  }

If arguments.length is 1, then there is no arguments[1], so you are just sending undefined to sumTwoAnd(b).

  function sumTwoAnd(c){
    return c+arguments[0];
  }

In this function c and arguments[0] are the same thing (and always undefined as explained above). So your sumTwoAnd tries to double undefined which doesn’t work because undefined is not a number. It returns NaN and therefor so does addTogether.

Here:


#4

addTogether(2)(3) is the correct syntax for this challenge.


#5

yupp i got it wer m getting wrong…but how to fix this…
in else if part i have changed the b=arguments[0] and when m returning sumTwoAnd(x)then its showing error: x is not defined


#6

Here’s another hint:
addTogether(2)(3);
The way for this to work is for addTogether(2) to return a function which expects a single argument.


#7

thats what m doing…sumTwoAndis that function


#8

No you aren’t. You are calling sumTwoAnd(b) and returning its return value, which is not a function either.

function returnsSix(arg) {
    return 6;
}
function myFunc() {
    return returnsSix(whatever); // returnsSix(whatever) becomes 6, which is then returned by myFunc
}

myFunc(); // 6

#9
b=arguments[0];
    return function(c){
      if(typeof c=="number")
      return b+c;
      else return undefined;
    };

now i got it…thank u so much!