I cant. seem to figure out why this isnt passing these tests:
addTogether(5)(7)
should return 12.
addTogether("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
should return undefined
.
**Your code so far**
function addTogether() {
let firstArg = arguments[0];
console.log(typeof firstArg)
if(arguments.length > 1){
let secondArg = arguments[1];
if (argumentCheck(firstArg) !== undefined &&
argumentCheck(secondArg)!== undefined){
return firstArg + secondArg;
} else {
return undefined;
}
} if (arguments.length === 1) {
if (firstArg === undefined){
return undefined;
} else {
return function(secondArg) {
checkArgAndAddIfValid(firstArg,secondArg)
}
}
}
}
function argumentCheck(argument) {
if(typeof argument !== 'number'){
return undefined;
} else {
return argument;
}
}
function checkArgAndAddIfValid(first,second){if (argumentCheck(first) !== undefined &&
argumentCheck(second)!== undefined){
return first + second;
} else
{
return undefined;
}
}
console.log(addTogether(5)(7));
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36
Challenge: Arguments Optional
Link to the challenge: