Arguments Optional challenge tests passed in IDE

Tell us what’s happening:
Hello, my code passes all the tests for the Intermediate Algorithm Scripting: Arguments Optional challenge in my IDE but passes none in the free code camp browser (chrome)

Am I using some syntax that free code camp doesn’t like or am I missing something obvious?

Your code so far


function addTogether() {
argsArray = [...arguments]
const isNaNStrict = (num) => {
    return !(num === parseInt(num))
}



if (argsArray.some(isNaNStrict)) {
    return undefined
}

else if (argsArray.length == 2) {
    return argsArray[0] + argsArray[1]
}

else {
    return addToArg = (num) => {
        if (isNaNStrict(num)) {
            return undefined
        }
        else return argsArray[0] + num
    }
}


}


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/81.0.4044.138 Safari/537.36.

Challenge: Arguments Optional

Link to the challenge:

You need to declare the argsArray (i.e. let argsArray = ......).

With this change I get the following results:

addTogether(2, 3) should return 5.

Passed

addTogether(2)(3) should return 5.

Failed

addTogether("http://bit.ly/IqT6zt") should return undefined.

Passed

addTogether(2, "3") should return undefined.

Passed

addTogether(2)([3]) should return undefined.

Failed

Hi, ty. I noticed i had missed the const/let just after I posted! For me those final two conditions pass in VScode, any idea why not in FCC?

I am suspicious of your isNaNStrict. Why not try typeof?

Ok, typeof is something i hadn’t used but it is useful

Turns out the issue was actually similar to my first mistake, I wasn’t defining the ‘addToArg’ function at the bottom properly. Defining at the top with const passes the tests. ty for your help :slight_smile:

1 Like