Arguments optional help on debug

I cant. seem to figure out why this isnt passing these tests:

addTogether(5)(7) should return 12.

addTogether("https://www.youtube.com/watch?v=dQw4w9WgXcQ") should return undefined .

  **Your code so far**

function addTogether() {
let firstArg = arguments[0];
console.log(typeof firstArg)
if(arguments.length > 1){
  let secondArg = arguments[1];
  if (argumentCheck(firstArg) !== undefined &&
  argumentCheck(secondArg)!== undefined){
    return firstArg + secondArg;
  } else {
    return undefined;
  } 
  
} if (arguments.length === 1) {
  if (firstArg === undefined){
    return undefined;
  } else {
    return function(secondArg) {
        checkArgAndAddIfValid(firstArg,secondArg)
    }
  }
}

}


function argumentCheck(argument) {
if(typeof argument !== 'number'){
  return undefined;
} else {
  return argument;
}
}

function checkArgAndAddIfValid(first,second){if (argumentCheck(first) !== undefined &&
  argumentCheck(second)!== undefined){
    return first + second;
  } else 
  {
    return undefined;
  }
}

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

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

Challenge: Arguments Optional

Link to the challenge:

Can you explain what this is doing?

My apologies, I should’ve included notes. The section above it should run only if there is more than one argument. The snippet you are showing is to run if there is only one argument if the checked value equals undefined (now that I’m typing this I realize I didn’t argumentCheck(firstArg)) . If the firstArg gets checked in argumentCheck is true for undefined then it returns undefined else it runs it through the check and add function.

I changed it to

else if (arguments.length === 1) {
    if (argumentCheck(firstArg) === undefined){
      return undefined;
    } else {
      return function(secondArg) {
          checkArgAndAddIfValid(firstArg,secondArg)
      }
    }
  }

which makes sense because i forgot to boolean check it there have to debug the sumof(5)(7) still giving me an error

That’s the hardest case.

This still seems strange to me. That function you are returning doesn’t have a return value.

Thanks a ton for helping in the way you did, you’re awesome! so yea it wasn’t returning for a reason lol. I forgot to make it return the function!

1 Like