Tell us what’s happening:
I have been working on the intermediate algorithm scripting challenge called “arguments optional”.
From my debugging efforts so far it looks like the problem is in returning a function correctly in the case that argument 2 is not given.
I have tested the function and it does exactly what it is supposed to do.
However, when I return that function in my code, it fails the tests.
I have checked and searched everything. I seem to be doing things exactly the same way as solution 1. I do not understand at all why my code is not working.
Can anybody point me into the right direction?
**Your code so far**
function addTogether(num1, num2) {
function checkNum(num){
if(typeof(num) !== "number"){
return undefined;
} else {
return num;
}
}
function adds(add2){
if(checkNum(add2)){
return num1+add2;
} else {
return undefined;
}
}
if(!checkNum(num1)||!checkNum(num2)){
return undefined;
} else if(checkNum(num1)&&checkNum(num2)){
return num1+num2;
} else if(num2==undefined){
return adds(add2);
}
}
addTogether(2,3);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0
.
Challenge: Arguments Optional
Link to the challenge: