My code passes for the 1st, 3rd & 4th tests but I’m unsure of where to go from here. For the next test of addTogether(2)(3) I’m guessing that under my else statement I have to write another function that takes 3 as a parameter and adds it to 2 which was input in the original function? Is this right?
I’m running into trouble if this is correct as I can’t use the arguments object to access (2)(3) I get an error saying TypeError: addTogether(…) is not a function. Where would I take it from here?
This was a tricky problem … i felt we did nothing to prepare us for this and understand why people are confused by it so im going to give some help
here is a link … its not doing the problem for you but its doing a section that i think you havent a understanding of. And with what you have and this you might be able to figure it out … or else youll have further questions.
link would not work properly when you click it … so copy whats between the brackets and paste into a new tab and it will work
I’ve considered this, though I’m not sure how to go about doing that. In this exercise if I have the arguments addTogether(2)(3); for example I get the error addTogether is not a function. This happens before any code runs, so I’m not sure how I’d even go about accessing the arguments object.
when you are doing addTogether(2)(3) you are always going to fail here and return undefinded and then get … addToghether is not a function error … as you are checking for two arguments and only sending one it fails and returns undefined … as addToghether(2) is only one arg … the (3) is not sent initially but is a parameter for the returned function (which you haven’t created yet) and is a self invoked function call with 3 as a parameter.
Did you check out my post … it shows how to return the function you need to create and its called by the second ()
you need to check initially how many parameters are sent … if 2 are sent (2,3) you return x+y … if one parameter is sent (2)(3) … looks like two but is only one … you need to return a function that takes a y parameter eg 3 then this function is run and it adds x which is 2 and y which is 3 … other than that you just need to check if the parameters sent are numbers.
I apologize, when I first read your message the link you included wasn’t working, but it does now. Thank you for explaining why my original check for undefined was failing, that makes a lot more sense now. I was having trouble understand that only 1 of those arguments was going into the function at a time, and therefore the second argument I was expecting to include wasn’t there. Let me have a further look at this and see if I can get any farther.
I really appreciate your assistance on this On a side note I’m thinking recursion might be a bit of a sticking point for me. If you know any outside resources that can help me practice and get this concept down I’m all ears.