Tell us what’s happening:
My code is getting stuck on the second test requirement, addTogether(2)(3). when i print out args it returns [2] rather than [2, 3].
This code does not work using 2 separate arguments. args[i] = arguments[i] does not return [2, 3] when calling addTogether(2)(3).
Your code so far
function addTogether() {
let args = new Array(arguments.length);
for (let i=0; i<args.length; i++) {
if (typeof arguments[i] !== 'number') {
return undefined;
} else {
args[i] = arguments[i];
};
};
if (args.length===2) {
return args[0] + args[1];
} else if (args.length===1) {
let c = args[0];
return ((x) => {
if (typeof x!== "number") {
return undefined;
} c + x;
});
};
};
addTogether(2)(3);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional