Currying application not working. Did based on last tutorial in Functional Programming (Javascript)

Tell us what’s happening:
Hello! I’m trying to use the currying application for the return function but somehow it doesn’t seem to work. Maybe one of you see my mistake? The error is in the return function base on the condition that the second argument is a number.
I put in some comments to make it easier for you to read my code. I hope it helps

  **Your code so far**

function addTogether() {
//condition: 1 argument
if (arguments.length === 1) {
  //check type of arg
  if (typeof arguments[0] === "number") {
    //tried using currying
    return function(second){
      //check type of next argument
      if (typeof second === "number") {
        return arguments[0] + second;
      } else {
        return undefined;
  //undefine if not type number
  } else {
    return undefined;
//condition: 2 arguments
} else if (arguments.length === 2) {
  //ensure both inputs are numbers
   if (typeof arguments[0] === "number" && typeof arguments[1] === "number") {
     return arguments[0] + arguments[1];
   } else {
     return undefined;
//condition: arguments > 2
} else {
  return undefined;

  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15

Challenge: Arguments Optional

Link to the challenge:

If you add


at the bottom, it prints 14, which means it’s adding 7+7. Why?

Because arguments[0] is now referring to the arguments of the returned function, to which you just passed 7, which is also second. So you need to use a variable that is not arguments[0] to hold the 5.

Oh thanks so much! :blush:

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