Failing 2 Tests on Arguments Optional

Tell us what’s happening:
Describe your issue in detail here.
I am failing 2 Tests on arguments optional. Those ones which have currying arguments. I don’t know how to access those currying arguments. I have check on Google but I could not find any correct solution. Can somebody help me?

  **Your code so far**

function addTogether() {
let args = [...arguments];
for(let i = 0; i < args.length; i++) {
  if(typeof(args[i]) !== "number") {
    return undefined;
  } else {
    return args.reduce((acc, val) => acc + val)
  }
}
}

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

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36

Challenge: Arguments Optional

Link to the challenge:

This for loop is making your code difficult to fix. I would remove this loop. Instead only consider one argument or two arguments separately.

function addTogether() {
  let args = [...arguments];
  if(typeof(args[0]) === "number" && typeof(args[1]) === "number") {
    return args[0] + args[1];
  }
}
console.log(addTogether(5, 5));
//Returns 10
console.log(addTogether(2, "3"));
//Returns undefined
console.log(addTogether(2)([3]));
//TypeError: addTogether(...) is not a function

I have remove the for loop but I keep failing the tests which include currying. Any idea how to solve this.

you need to do something different if args[1] doesn’t exist- or what if it’s invalid?

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