'Arguments Optional' Issue

Tell us what’s happening:
The code seems to work outside of the last check, when the second arg is a number inside an array. The confusing part is that with those args (2,[3]), the console.log directly before ‘return undefined’ is functioning as I would expect it to, but undefined isn’t being returned.

   **Your code so far**

function addTogether() {

 let len = Array.from(arguments);
 //let len = Object.values(arguments);
 console.log(len.every(x => typeof x === 'number'));

if(len.every(x => typeof x === 'number')){
     case 2:
     console.log('adding two');
       return len[0] + len[1];
     case 1:
       return function(arg){
         return len[0] + arg;
  console.log('returning undefined');
   return undefined;

   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0

Challenge: Arguments Optional

Link to the challenge:

Undefined is being returned, you’re just not logging what is being returned.

console.log(addTogether(2,[3]))  // undefined

Why is the “addTogether(2)([3])should returnundefined`” check failing then? That’s what I’m confused about.

Thanks for responding.

that’s the situation where the argument length is one, and the function returns a function - but this second function argument’s type is not checked in your code

1 Like

Oh wow, I was reading the text as (2,[3]) and not (2)([3]) haha. Got it.