Arguments Optional issue

Arguments Optional issue
0

#1

I don’t really understand this challenge. In first place, is think is impossible to code, for example:

addTogether(2)(3);

Isn’t that impossible? When I try to pass that and trying to execute the code in a browser console (and even in the free code camp code editor), I got the next error:

Uncaught TypeError: addTogether(…) is not a function. So, what’s going on? :frowning:


#2

It’s not impossible, but it’s not easier either!
What you’re seeing with addTogether(2)(3); is chaining.
I’m guessing that addTogether(1, 2); would make sense to you because we know the pattern functionName(parameters). What this exercise is teaching you is that functions can return functions as as well as other values (like a string or a number or an array). This is because functions are “first class objects”.
What you are tasked to do is to create a function, addTogether that returns a number if it gets 2 parameters and returns a function if it gets only 1 parameter.
Remember what I said about chaining? We have addTogether(2)(3);, first addTogether(2) executes and returns a function. So addTogether(2)(3); becomes returnedFunction(3);.


#3

Thank you very much!