'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);
 console.log(len);
 //let len = Object.values(arguments);
 console.log(len.length);
 console.log(len.every(x => typeof x === 'number'));

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

addTogether(2,[3]);
   **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.
Thanks!

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