Tell us what’s happening:
I having trouble with #5 and #8 .
#5 - my code seems to think that null and undefined are the same. I’m not sure how to differentiate between the two.
#8 if never seen a function be called like this addTogether(5)(7) - i thought a function had to one set of brackets (e.g addTogether(5, 7) ) - so because i’ve never seen that before i don’t know how to treat it
Your code so far
function addTogether(arg1, arg2 = null) {
if (typeof arg1 !== 'number') {
return undefined
} else if (typeof arg2 !== 'number') {
if (arg2 !== null) {
return undefined
} else {
return function() {
}
}
}
else {
return arg1 + arg2
}
}
console.log(addTogether(2, null));
console.log(addTogether(5, undefined));
console.log(addTogether(5)(7));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0
Challenge Information:
Build an Optional Arguments Sum Function - Build an Optional Arguments Sum Function
https://www.freecodecamp.org/learn/full-stack-developer/lab-optional-arguments-sum-function/build-an-optional-arguments-sum-function
ILM
September 4, 2025, 9:50am
2
you can do this because addTogether(5) should return a function, and you can call a function adding (7) next to it
can you give more details to this please?
be careful of what comparison you use
ILM
September 4, 2025, 9:51am
3
wait, I think you have met an issue with default values
if you do this, the default value of the second parameter is given to it
ILM
September 4, 2025, 9:53am
4
are maybe the rest parameter or the arguments object taught before this lab? it looks like they are needed, and if they are not we may have put the lab in the wrong place
I have created an issue for this
opened 09:59AM - 04 Sep 25 UTC
scope: curriculum
status: waiting triage
full stack cert
https://www.freecodecamp.org/learn/full-stack-developer/lab-optional-arguments-s… um-function/build-an-optional-arguments-sum-function
this lab seems to need the [rest parameters syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) or the [`arguments` object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments) and we have not taught those before this point, I am not sure they are taught at all. We could revert this lab to `"isUpcomingChanges": true` until we add those topics to the curriculum
ok, i’ve fixed #8 . Just #5 to go
else if (typeof arg2 !== 'number') {
if (arg2 !== null) {
return undefined
are you saying i should try != instead? that still doesn’t work
or is the lab in the wrong place like you said and it’s not what i’m doing that is the problem?
Please share your full updated code.
ILM
September 4, 2025, 1:12pm
7
the issue is that you should return a function with addTogether(5) but return undefined with addTogether(5, undefined)
in both of these cases arg2 is null, your approach can’t distinguish them
updated code:
function addTogether(arg1, arg2 = null) {
if (typeof arg1 !== 'number') {
return undefined
} else if (typeof arg2 !== 'number') {
if (arg2 !== null) {
return undefined
} else {
return function(number) {
if (typeof number !== 'number') {
return undefined
} else {return arg1 + number}
}
}
}
else {
return arg1 + arg2
}
}
so what approach do i need to take?
Use console.log to determine what happens to arg2 in each case.
function addTogether(arg1, arg2 = null) {
console.log(arg2)
console.log(addTogether(5, undefined))
console.log(addTogether(5))
You’ll need to find a way to differentiate these inputs. Maybe you can’t use arg2 = null ?
i changed it to rest parameters and it works
thanks for your help
1 Like
ILM
September 5, 2025, 7:12am
12
is that something you have learned in the curriculum? or is that knowledge coming from somewhere else?
1 Like
i did Google it - so that is where i learned how to use it for this project.
I thought it had been mentioned somewhere earlier in the curriculum - not sure how in-depth it was though
ILM
September 5, 2025, 8:26am
14
Hampig
September 5, 2025, 8:37pm
15
yeah, i didn’t even consider i could use rest parameters there, i had to look it up and found a different way to check the number of arguments
1 Like