JS won't return undefined, i don't know why

Tell us what’s happening:

Why it won’t return undefined when i test:


but the code works when it gets to the same point with console.log

Code still return undefined for

addTogether(2, “3”)

Your code so far

function addTogether() {  
if (typeof arguments[0]=="number"){
  if (arguments.length == 1){
    let a = arguments[0]
    return function(b){
  else if(typeof arguments[1]=="number") {
  else {
    return undefined}
else {return undefined}


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.

Challenge: Arguments Optional

Link to the challenge:

Hi and welcome to the forum.

Your code is pretty close.
The function that you return needs to check if b is a valid input.

hi thanks for pointing out my one mistake, i almost hardcoded them lol…

but the first part of else return undefined, it doesn’t work. when i change them to console.log(“test”), it was logged, have idea why? thanks for replying

well i just did what you told me and it works, care for explanation?

The last test case is checking that your returned function checks that the new argument is also a number.

That’s why addTogether(2)([3]) didn’t pass. Your function previously returned whatever JS computes 2 + [3] as instead of returning undefined.

1 Like