Arguments Optional Trouble

Tell us what’s happening:

Your code so far


function addTogether() {
var args = Array.from(arguments);
return args.some(n => typeof n !== "number") ?
undefined:
args.length > 1 ?
args.reduce((acc, n) => acc += n, 0):
(n) => typeof n === "number" ?
n = args[0]:
undefined;
}

addTogether(2,3);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:76.0) Gecko/20100101 Firefox/76.0.

Challenge: Arguments Optional

Link to the challenge:

I have five out of six correct in my code, but I can’t figure out what is wrong with the last.

What does the failing test say?

It says addTogether (5) (7) should return 12

Between three nested ternaries and the use of array methods this is really unpleasant to try to read (not to mention unnecessarily complicated).

If I parsed that correctly without taking the time to rewrite it more legibly, the case of
addTogether(5) (and by extension addTogether(5)(7)) would get you to this return value:

n = args[0]:

You are attempting to return an assignment.

I’m so confused that i am going to start over.

I really suggest doing this in a more straightforward way. Don’t try to make it as short as possible with ternaries. Coding isn’t golf.

Always remember - make clear code that works first. You can improve the code once it works.

2 Likes

I have completed that challenge. :+1:

2 Likes

Congratulations! I’m glad you figured it out!

1 Like

Thank you very much! I love freecodecamp so much and everyone that is a part of it!

4 Likes