Tell us what’s happening:
If I run the code below with addTogether(2,3);
I end up passing 3/5 tests.
Failed tests being:
addTogether(2)(3)
should return 5.
addTogether(2)([3])
should return undefined.
If I run the code below with addTogether(2)(3);
I end up failing all 5 tests.
Console is outputing: addTogether(...) is not a function
Where did I go wrong?
Your code so far
function addTogether() {
let param1 = arguments[0];
let param2 = arguments[1];
if (typeof param1 !== "number" || typeof param2 !== "number") {
return undefined;
}
if (arguments.length === 2) {
return param1 + param2;
}
else if (param2 === undefined) {
return function x (num) {
if (typeof num !== "number") {
return undefined;
}
else {
return param1 + num;
}
}
}
}
addTogether(2,3);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional