Tell us what’s happening:
My code won’t pass the last challenge, and I’m confused by it. It looks to me like a multiplication of the output of my function (which in that case would be another function since there’s only one argument) with the array, [3]. But the output of that would have nothing to do with my function, would it? And I know my function is working correctly in outputting another function when there’s only one argument because it’s passing the other tests. I don’t know how I’m supposed to pass this test.
**EDIT: On second thought, I guess the final challenge is passing the array [3] into the function output by calling addTogether(2). But I still don’t see why it’s not working since it passed Tests 4 and 5.
Your code so far
function addTogether() {
for (let i=0; i<arguments.length; i++) {
if (typeof arguments[i] !== 'number') return undefined;
}
if (arguments.length === 2) {
console.log("sum ", (arguments[0] + arguments[1]));
return (arguments[0] + arguments[1]);
}
else if (arguments.length === 1) {
let arg = arguments[0];
console.log("arg: ", arg);
let func = function(x) {
return x + arg;
}
return func;
}
}
addTogether(2,3);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0
.
Challenge: Arguments Optional
Link to the challenge: