Tell us what’s happening:
I don’t understand what the return function(arg2) does exactly.
How does the function get that we are looking for the second argument? Is arg2 something in JS that it knows we are looking for the second argument or how does work?
Your code so far
function addTogether() {
var checker = function(num) {
if (typeof num !== "number") {
return undefined;
} else return num;
};
if (arguments.length > 1) {
var a = checker(arguments[0]);
var b = checker(arguments[1]);
if (a === undefined || b === undefined) {
return undefined;
} else {
return a + b;
}
} else {
var c = arguments[0];
if (checker(c)) {
return function(arg2) {
if (c === undefined || checker(arg2) === undefined) {
return undefined;
} else {
return c + arg2;
}
};
}
}
}
addTogether(2, 3)
addTogether("http://bit.ly/IqT6zt")
addTogether(5)(7);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0
.
Challenge: Arguments Optional
Link to the challenge: