Intermediate Algorithm Scripting - Arguments Optional

Tell us what’s happening:
Describe your issue in detail here.

Hi, I’m passing most of the tests for this challenge, but I’m just stuck on how to account for numbers outside of the function(). (I’m still new to using these terms, so feel free to correct me as you help me out - thanks so much!)

As you can see in my code, for the function addTogether, if the arguments passed into the function are greater than 1 and if they are both numbers, the function runs and adds them together - if that’s not the case, it returns undefined. That works correctly.

Where I’m stuck are these problems here:

• addTogether(2)([3])`should return`undefined`

I’m not sure how to account for/place inside both of the numbers because they are sitting next to one another, but with the current placement of the (7) and the ([3]), I can’t access them inside of the addTogether function.

Any guidance appreciated, thank you!

``````function addTogether() {
let firstArgument = arguments[0];
let secondArgument = arguments[1];

if (arguments.length > 1 && typeof firstArgument === "number" && typeof secondArgument === "number"){
return firstArgument + secondArgument
} else {
return undefined
}
}
``````

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36`

Challenge: Intermediate Algorithm Scripting - Arguments Optional

what’s the point of returning a function like that? it doesn’t do anything.

Hi, I’m needing some advice regarding that last comment. I’m not sure how to access the (7) because it’s not being passed inside of the addTogether function() - instead, they numbers are in parenthesis, listed side by side. I am new to JS, and I’m not sure how to bring in that (7) - I’m still working on the remaining tests, but I’m stuck in particular with this part. Can you help give me a tip or a reference link to that? It’s not considered an argument because it’s not inside of the addTogether(_____, ______) function, but I need to access it somehow or put it inside.

Thank you so much!

When a call like `addTogether(5)(7)` is made, what is really happening is first is a call to `addTogether(5)` is made first. Since `5` is only one argument passed to the function, your `addTogether` function should return another function that adds the `5` to the argument passed to the function returned. That way the `(7)` part is really just calling the function returned by `addTogether`.

I will give you a simple algorithm for `addTogether` without writing the code:

If the function only receives one argument and the argument is a number, then return a function that looks similar to:

``````function (arg) {
return arg + the number (the single argument) passed to `addTogether` function.
}
``````

That made a lot of sense, thank you for taking the time to explain that, I’ll keep working on this - huge thanks!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.