Tell us what’s happening:
Describe your issue in detail here.
Why it returns [Function]
addTogether(5, undefined) should return undefined.
// tests completed
// console output
5
5
[Function]
Your code so far
function addTogether(a, b=0) {
if (typeof a !== "number" || typeof b !== "number") {
return undefined
} else if (b === "undefined") {
return undefined
}
if (a && b) {
if (typeof a === "number" && typeof b === "number") {
return a + b
}
} else if (!b) {
return function(c) {
if (typeof c !== "number") {
return undefined
}
return a + c
}
}
}
let addNums = addTogether(2)(3)
console.log(addNums);
addNums = addTogether(2, 3)
console.log(addNums)
addNums = addTogether(2, undefined)
console.log(addNums)
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 11; Nokia 3.4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Mobile Safari/537.36
Challenge: Intermediate Algorithm Scripting - Arguments Optional
Link to the challenge: