Tell us what’s happening:
Hello,
I am working on the section that wants me to create a function that sums two numbers. If either of the two arguments passed to the function are not numbers I am supposed to return undefined.
When I have just the code below, my function works just fine at filtering out all non numbers.
function addTogether() {
if (isNaN(arguments[0])||isNaN(arguments[1]))
return undefined;
}
However once I add the else if statement
else if(arguments.length == 2){
return arguments[0] + arguments[1];
}
It no longer weeds out some of the non number values and doesn’t return undefined for this statement.
addTogether(2, "3")
should return undefined
.
Why?
Thanks!
**Your code so far**
function addTogether() {
if (isNaN(arguments[0])||isNaN(arguments[1])){
return undefined;
}else if(arguments.length == 2){
return arguments[0] + arguments[1];
}
}
addTogether(2,3);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.61 Safari/537.36
Challenge: Arguments Optional
Link to the challenge: