Intermediate Algorithm Scripting - Arguments Optional

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

I am unable to pass the test fully can anyone help me

function addTogether() {
  const first = arguments[0];
  const second = arguments[1];

  if (typeof first === "number" && typeof second === "number"){

    if(Array.isArray(first) === false && Array.isArray(second) === false) {
      return first + second;

    } else if(arguments.length === 1) {
      return (third) => {

        if(typeof third === "number" && Array.isArray(first) === false && Array.isArray(third) === false) {
          return first + third;

        }
      }
    }
  }
}


console.log(addTogether(5));

Your browser information:

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

Challenge: Intermediate Algorithm Scripting - Arguments Optional

Link to the challenge:

It helps if you say more about what you have tried and where you are stuck fixing your code.


This means you are ignoring any case where the second argument is not provided

Am not able to pass the rest of the test

function addTogether() {
  const first = arguments[0];
  const second = arguments[1];

  if(arguments.length === 2) {
    if(checkArgument(first) === undefined || checkArgument(second) === undefined) {
      return undefined;
    } else {
    return checkArgument(first) + checkArgument(second);
    }
  } else if(arguments.length === 1) {
    return (third) => {
      if(typeof (first) === "number" || checkArgument(third) === undefined)   {
        return undefined;
      } else {
        return checkArgument(first) + checkArgument(third);
      }
    }
  }

  function checkArgument(num) {
    if(typeof num !== "number") {
      return undefined;
    }else {
      return num;
    }
  }
}


console.log(addTogether("https://www.youtube.com/watch?v=dQw4w9WgXcQ"));

i tried a different approach which for the large portion pass the test with the exception of addTogether("https://www.youtube.com/watch?v=dQw4w9WgXcQ") should return undefined .

You are always returning a function here, but what do the instructions want if there is only one argument and it’s not a number?

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