Let's discuss Arguments Optional

Let's discuss Arguments Optional
0

#1

I happen to have recently read a chapter on Closures so the challenge is well timed. I have a feeling the solution is simple but - I don’t understand what its asking and can’t figure out what I’m supposed to do for the life of me. I started read search ask and looked at hint one. I’m thinking about calling this one an L and just reading the explanation of the answer and starting from there. This isn’t a question but thought I’d share.


#2

You can do this. Let’s go through the instructions:

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.

So, if there are two arguments, the function returns their sum. I’m sure you’d have no trouble doing that one. But if there’s just one argument, the function returns another function.

Calling this returned function with a single argument will then return the sum:

var sumTwoAnd = addTogether(2);

sumTwoAnd(3) returns 5.

The function that is returned by the first will always add 2 to whatever it’s passed. That’s the real trick to this problem. How do you return a function that will always add 2?


#3

Thanks for this. I came at it with fresh eyes today and was able to get 1, 3, and 4 to pass but 2 and 5 I don’t get at all. There are two items in separate parentheses and it doesn’t recognize that as a function. Probably will take another fresh look tomorrow.