Tell us what’s happening:
i need help here i can’t pass the test #5 it return a function and it require to return undefined , anyhelp here
Your code so far
function addTogether(arg1, arg2 = null) {
if(typeof arg1 == 'number') {
if(typeof arg2 == 'number') {
return arg1 + arg2
}
if(arg2 == undefined) {
return function(x) {
if(typeof x == 'number') {
return arg1 + x
}
}
}
}
}
console.log(addTogether(2)(5))
console.log(addTogether(5))
console.log(addTogether(5, undefined))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Challenge Information:
Build an Optional Arguments Sum Function - Build an Optional Arguments Sum Function
ILM
October 7, 2025, 8:54am
2
you need to change your approach
add console.log({arg1, arg2}) and see what comes out of it
you can’t distinguish between addTogether(5) and addTogether(5, undefined) with your approach
you may want to go back to the last theory block before this lab
wait but why i should log arg1, arg2 in an object ??
ILM
October 7, 2025, 8:58am
4
it’s an habit I have, it adds the variable name automatically so I don’t need to label the log
the thing is you should see arg2: null for both cases
1 Like
ok i still didn’t get it , i will review the theory you refer to then i may understand
ILM
October 7, 2025, 9:23am
6
this was pointing out an issue with your correct approach, now you need to find the correct approach, that theory block can be your starting point
i feel i started to smell the solution , the key is arguments object
ILM
October 7, 2025, 9:46am
8
first look at the second lesson, arguments is a bit outdated, the thing in the second lesson is more modern
1 Like
yes i had knowledge about rest parameters but i still donno how to use it with this issue , limme check
ILM
October 7, 2025, 10:11am
10
what’s the main difference between when you should return a function, and when not?
the main difference is the undefined if it’s a real value or it’s for undeclared argument
i feel something ?
if i tested the length for rest param and i get the length is only 1 i should return function if the length is more than 1 i return undefined value ?
am i true ?
so silence means acceptance
i work on it for now
ILM
October 7, 2025, 12:42pm
14
or silence means “I have not read your message yet”
try it, see what happens
1 Like
sorry but, i like your way man
iam so sorry for that too . i just feel exciting somehow , although i did not solved the problem still
i started to get despair somehow , i tried and tried , i restarted and commented and did more than brain storming
Hi if you didn’t see the solution i can give your a hint use destruction args like this addTogether(...args) after do this change your approach . Sorry my english is not very good if you don’t understand send me a message
yes i know destructuring , let me try to do it myself first if i failed i will back to you again
1 Like