Tell us what’s happening:
one of the functions I am supposed to pass is this :
addTogether(5)(7)
could anyone explain to me this function call? thanks
Your code so far
function addTogether() {
let sum = 0;
let flagOfTwo = 0;
let flagOfOne = 0;
let undeFlag = 0;
for (let i = 0; i < arguments.length; i++) {
if (arguments.length > 1) {
sum += arguments[i]
flagOfTwo = 1;
}
}
if (flagOfTwo) {
return sum;
}
}
addTogether(2,3)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Sorry, I don’t know the answer console.log doesn’t work inside. which I assume because it is a function but I am not sure exactly why.
I thought it inherents outside functions?
I assume you are talking about inside your returned function, oneArg? its because that’s a new function with its own arguments. When you call with addTogether(5) that turns into oneArg because you have set it to return that function. Then with the (7) after addTogether(5) like this “addTogether(5)(7)” basically what you are doing is calling oneArg(7). So its arguments would be 7.
In addTogether the first argument would be 5, but like a said after that its returning the function oneArg, where its first argument would be 7. oneArg has access to variables and parameters from addTogether with closure, but with the arguments[0] inside oneArg its looking at its own arguments first. You need to somehow grab the 5 from addTogether in oneArg.