Intermediate Algorithm Scripting - Arguments Optional

Tell us what’s happening:
Describe your issue in detail here.
I have a question: In this code:
if (second === undefined)
return (second) => addTogether(first, second)
console.log(second);
how does the computer know to add 2 numbers if we do not add something like + ? Thank you.

   **Your code so far**
function addTogether() {
const [first, second] = arguments;

 if (typeof(first) !== "number")
   return undefined;
 if (second === undefined)
   return (second) => addTogether(first, second)
   console.log(second);
 if (typeof(second) !== "number")
   return undefined;
 return first + second;
}

console.log(addTogether(5)(7));
   **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:

because when second is defined it returns first + second

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