Tell us what’s happening:
Describe your issue in detail here.
It’s passing everything but the “undefined” tests, and I’m not sure why. The condition is there and it’s in the beginning of the conditions, so I would assume it would catch all undefined elements first…
Your code so far
function addTogether() {
// make a copy of the arguments passed in using the "arguments" object
let args = [...arguments];
// loop through the args array using a "for" loop
for (let i = 0; i < args.length; i++) {
// create a conditional chain, starting with returning "undefined" if none of the arguments are numbers
if (typeof args[i] !== 'number') {
return undefined;
} else if (args.length === 1) {
// if there is only one argument in the arguments list, return a function that takes in a number and calls the addTogether function on that passed in number and the element positioned at args[0] (the only element in the array)
return function addNum(num) {
return addTogether(args[0], num);
}
} else {
// otherwise, return the addition of the two indices of args
return args[0] + args[1];
}
}
}
addTogether(2,3);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0
Challenge: Intermediate Algorithm Scripting - Arguments Optional
Link to the challenge: