I wonder why the tests are not passing even though the outputs are correct

I pass all tests except two
But the outputs do match.

**Please excuse the mess getting it to work was the first priority**

function addTogether(...arr) {
//console.log(arguments.length);
if (arguments.length == 1 || arguments.length == 2) {
  if (arguments.length == 1) {
    if (typeof arguments[0] !== "number") { return undefined; }
    else {
      let first = arguments[0];
      //console.log(arguments[0]);

      function addT(a) {
        if (typeof a !== "number") { return undefined; }
        else { return first + a; }
      }
      return addT(7);
    }
  }

  else {
    if (typeof arguments[0] !== "number" || typeof arguments[1] !== "number") { return undefined; }
    else { return arguments[0] + arguments[1]; }
  }


}
else return undefined;

//console.log(arguments.length);

}


console.log(addTogether(5));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.177

Challenge: Arguments Optional

Link to the challenge:

Formatted for easier reading:

function addTogether(...arr) {
  //console.log(arguments.length);
  if (arguments.length == 1 || arguments.length == 2) {
    if (arguments.length == 1) {
      if (typeof arguments[0] !== "number") {
        return undefined;
      } else {
        let first = arguments[0];
        //console.log(arguments[0]);

        function addT(a) {
          if (typeof a !== "number") {
            return undefined;
          } else {
            return first + a;
          }
        }
// LOOK RIGHT HERE
        return addT(7);
// LOOK RIGHT HERE
      }
    } else {
      if (typeof arguments[0] !== "number" || typeof arguments[1] !== "number") {
        return undefined;
      } else {
        return arguments[0] + arguments[1];
      }
    }
  } else {
    return undefined;
  }
  //console.log(arguments.length);
}


console.log(addTogether(5));

In the place I have highlighted, are you returning the correct thing?

1 Like

Yes. When we say return addT(7). We are saying call addT(7) and put what it returns there. So what addT(7) returns is 7+5=12.

So what we are saying is return 12 right? Which is correct?

I mean if the addT(7) was not there then we would be returning a function which is true right.

Why return addT(7) though?

The instructions say

If only one argument is provided, then return a function that expects one argument and returns the sum.

1 Like

Thank you. I get it. I had returned the function value instead of the function. (I actually admit I looked up the solution for this one at the end after passing all tests except 1-2 because I was not understanding what the question was saying when it said create a function which expects an argument etc which I did but I was not sure how exactly to passed the test so I took a quick look at the function implementation.

Last one part of this(the function implementation) and the prime numbers one were the only ones I looked though. Rest I did by myself. I did look up and studied all the solutions one by one after I passed the test which is what took a lot of time, effort and pain.

Looking and traversing through the given solutions is much harder and painful than actually creating your own solution as in the solution they complicate small things so much like even something as basic as create a array from 1 to 5.

Some of the provided solutions are definitely a bit convoluted. Mine doesn’t look like any of them:

function addTogether(a, b = null) {
  if (b === null && typeof a === "number") {
    return c => typeof c === "number" ? a + c : undefined;
  }
  if ((typeof a !== "number") || (typeof b !== "number")) {
    return undefined;
  }
  return a + b;
}
1 Like

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.

1 Like

If you say so, though I don’t see how it’s any worse than the existing honor system with official solutions.

1 Like

Simple rules:

Users can look up the guide post solutions if they want to, though doing so before you solve the problem is not recommended.

Users can start topics asking for feedback on their solution where other users discuss the original user’s solution.

Users cannot just throw solutions, solicited or unsolicited, into non-feedback threads.

Pretty straightforward.

1 Like