hello,
could someone tell me y my code can not pass the last condition?
function addTogether() {
let [arg1, arg2] = arguments;
function isNum(num) {
return Number.isInteger(num);
}
if (!isNum(arg1)) {
return undefined;
}
else if (isNum(arg1) && isNum(arg2)) {
return arg1 + arg2;
}
else if (!arg2) {
return function(newArg) {
if (isNum(newArg)) {
return arg1 + newArg;
}
}
}
}
Your code so far
function addTogether() {
let [arg1, arg2] = arguments;
function isNum(num) {
return Number.isInteger(num);
}
if (!isNum(arg1)) {
return undefined;
}
else if (isNum(arg1) && isNum(arg2)) {
return arg1 + arg2;
}
else if (!arg2) {
return function(newArg) {
if (isNum(newArg)) {
return arg1 + newArg;
}
}
}
}
console.log(addTogether(5, undefined))
console.log(addTogether(2, "3"))
console.log(addTogether(5)(7))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Arguments Optional
Link to the challenge: