# Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional

Tell us what’s happening:
I am getting the result with console.log, but I am not passing the tests

``````

if(Number.isInteger(arguments[0]) && Number.isInteger(arguments[1])){

return arguments[0]+arguments[1]

}else if(Number.isInteger(arguments[0])){

return arguments[0]

}
}

function sumTwoAnd(){

}

console.log(sumTwoAnd(2))

/*Intermediate Algorithm Scripting: Arguments Optional
Create a function that sums two arguments together. If only one argument is provided, then return a function that expects one argument and returns the sum.

For example, addTogether(2, 3) should return 5, and addTogether(2) should return a function.

Calling this returned function with a single argument will then return the sum:

sumTwoAnd(3) returns 5.

If either argument isn't a valid number, return undefined.

*/

``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36`.

Challenge: Arguments Optional

I am not getting the result, I am getting undefined. Your function needs to return a function if is called with only one argument.

1 Like

My teacher, how may I set the second condition? “If only one argument is provided, then return a function that expects one argument and returns the sum.” I already set a function and I do not know how to make it work properly.

``````function addTogether() {

if(Number.isInteger(arguments[0]) && Number.isInteger(arguments[1])){

return arguments[0]+arguments[1]

}else{

function sumTwoAnd() {

}

}

}

/*

Intermediate Algorithm Scripting: Arguments Optional

Create a function that sums two arguments together. If only one argument is provided, then return a function that expects one argument and returns the sum.

For example, addTogether(2, 3) should return 5, and addTogether(2) should return a function.

Calling this returned function with a single argument will then return the sum:

sumTwoAnd(3) returns 5.

If either argument isn't a valid number, return undefined.

``````

You have a function, `addTogether()`, which currently takes no arguments. The function needs to take two arguments, as the example in the lesson shows.

Also from the lesson text:
“If only one argument is provided, then return a function that expects one argument and returns the sum.”
The key phrase here is return a function.

I hope this helps point you in the right direction.

1 Like
``````function addTogether() {

if(Number.isInteger(arguments[0]) && Number.isInteger(arguments[1])){

return arguments[0]+arguments[1]

}else {

return function(){

if(Number.isInteger(arguments[0])){

return arguments[0]+arguments[0]

}

}

}

}

`addTogether(2)([3])` should return undefined. I only need to complete that test. What may I do?

``````function addTogether() {

if(arguments.length===1 && Number.isInteger(arguments[0]) ){

let a=arguments[0]

return function (b){

return a+b

}

}else if(arguments.length===2 && Number.isInteger(arguments[0])&& Number.isInteger(arguments[1])){

return arguments[0]+arguments[1]

}else{

return undefined;

}

}

/*Intermediate Algorithm Scripting: Arguments Optional

Create a function that sums two arguments together. If only one argument is provided, then return a function that expects one argument and returns the sum.

For example, addTogether(2, 3) should return 5, and addTogether(2) should return a function.

Calling this returned function with a single argument will then return the sum:

sumTwoAnd(3) returns 5.

If either argument isn't a valid number, return undefined.

``````function addTogether() {

if(arguments.length===1 && Number.isInteger(arguments[0]) ){

let a=arguments[0]

return function c(b){

if(Number.isInteger(b)){

return a + b

}

}

{

}

}else if(arguments.length===2 && Number.isInteger(arguments[0])&& Number.isInteger(arguments[1])){

return arguments[0]+arguments[1]

}else{

return undefined;

}

}