Tell us what’s happening:
Hello! I’m trying to use the currying application for the return function but somehow it doesn’t seem to work. Maybe one of you see my mistake? The error is in the return function base on the condition that the second argument is a number.
I put in some comments to make it easier for you to read my code. I hope it helps
**Your code so far**
function addTogether() {
//condition: 1 argument
if (arguments.length === 1) {
//check type of arg
if (typeof arguments[0] === "number") {
//tried using currying
return function(second){
//check type of next argument
if (typeof second === "number") {
// I THINK THE ERROR/MISTAKE IS HERE
return arguments[0] + second;
} else {
return undefined;
}
}
//undefine if not type number
} else {
return undefined;
}
//condition: 2 arguments
} else if (arguments.length === 2) {
//ensure both inputs are numbers
if (typeof arguments[0] === "number" && typeof arguments[1] === "number") {
return arguments[0] + arguments[1];
} else {
return undefined;
}
//condition: arguments > 2
} else {
return undefined;
}
}
addTogether(2,3);
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15
Challenge: Arguments Optional
Link to the challenge: