Intermediate Algorithm Scripting - Arguments Optional

Tell us what’s happening:
Describe your issue in detail here.
My code below here works in most of the tests, excepts for these two:
“addTogether(5)(7)”
and “addTogether(2, “3”)”
when I console.log them, it just appears:“TypeError: addTogether(…) is not a function”. Can you explain that to me? Thank you so much.

   **Your code so far**
function addTogether() {
 const addTogetherArgs = arguments
 console.log(addTogetherArgs)
if(typeof addTogetherArgs[0] !== "number" || typeof addTogetherArgs[1] !== "number"){
 return undefined
}
else if(arguments.length === 1){
return function addNumTwo(num2){
 return addTogether(addTogetherArgs[0], num2)
}
}

else {
 return addTogetherArgs[0] + addTogetherArgs[1]
}
}

console.log(addTogether(2)([3]));
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36

Challenge: Intermediate Algorithm Scripting - Arguments Optional

Link to the challenge:

If there is not a second argument, then the second argument is not a number

1 Like

Thank you, but why it shows that error:TypeError: addTogether(…) is not a function

Because you never return a function

1 Like

But I thought in here, I have returned this function addTogether

But that never happens because when you only have one argument, then the second is automatically not a number.

1 Like