Help in Solving Arguments Optional Requested

Hello. I am working on Arguments Optional in the intermediate scripting section. https://www.freecodecamp.org/challenges/arguments-optional

I am receiving the error message: “TypeError: Num is not a Function”. It is saying that variables first and second are used out of scope. Could I get some help with this?


function addTogether() {
  //turn object into array
  var nums = [].slice.call(arguments);
  //call a function on every item in array
  if (!nums.every(function(num){
    //if the array contains only numbers, return numbers
    //Otherwise, return undefined
    return typeof(num) =='number' ? num : undefined; 
  }))
    //assign first and second nums in array to variables
  var first = nums(arguments[0]);
  var second = nums(arguments[1]);
  if (arguments.length==2) {
    return first + second;
  } else {
    return undefined;
  }
  if (first) {
    return function(third) {
      return first + third;
    };
  } else {
    return undefined;
  }
  return false;
}

addTogether(2,3);

I am now getting 5 as the output; however, I’m still getting Xs for addTogether(2)(3) should return 5. and addTogether(2)([3]) should return undefined. I don’t know how to read them.

Here is my updated code:

function addTogether() {
  //turn object into array
  var nums = [].slice.call(arguments);
  //call a function on every item in array
  if (!nums.every(function(num){
    //if the array contains only numbers, return numbers
    //Otherwise, return undefined
    return typeof(num) =='number';
  })) 
    return undefined;
    //assign first and second nums in array to variables
  var first = nums[0];
  var second = nums[1];
  if (nums.length===2) {
    return first + second;
  } else {
    return undefined;
  }
  if (first) {
    return function(obj) {
      return first + obj;
    };
  } else {
    return undefined;
  }
}

addTogether(2,3);

Try putting breakpoint on your JS code in the browser and press F10 key to debug code line by line.

I’ve realized I have not learned how to debug properly. Do you know of any good tutorials that teach this? Thanks!