Tell us what’s happening:
I don’t know what the addTogether(2)(3) should equal 5; I think I have all the code to make that happen, but I don’t know what really happened.
Your code so far
function addTogether() {
let isInteger = true;
let argadder = arguments[0];
for(let i = 0; i < arguments.length; i++) {
if(typeof arguments[i] !== "number") {
isInteger = false;
}
}
if(isInteger === true) {
if(arguments.length === 2) {
return (arguments[0] + arguments[1]);
} else if (arguments.length === 1) {
return(function(arg) {
return(arg[0]) + argadder;
}
)
}
}
}
addTogether(2);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36.
function addTogether() {
// Check if the parameter is legal
const check = function(args) {
for (const arg of args) {
if (typeof arg !== 'number') {
return false
}
}
return true
}
if(!check(arguments)) {
return
}
const LENGTH = arguments.length
// Only one parameter, should return a function
if (LENGTH === 1) {
const TEMP = arguments[0]
return function(value) {
if(!check(arguments)) {
return
}
return TEMP + value
}
} else if (LENGTH === 2) {
// Two parameters, return the result of adding the two parameters
const [a, b] = arguments
return a + b
}
}
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.