Tell us what’s happening:
I understand the logic behind solving this problem, and though I have not yet tried the recommended method of solving it, I seem to have encountered a problem. Can someone help me understand why this test case keeps evaluating to false?
I’ve tested the second argument with Number.isInteger() and it’s proven to be a falsy value. Then, I test to ensure whether or not the if statement is executed, which it is. I also check to ensure that the function evaluates to “undefined” at the end, and it does.
So, why am I failing this test case? All other tests with non-integer values are passed. The only difference being that every other test case has string values or undefined values and not an array of integers. What’s going on?
Thanks in advance for your time and assistance!
Your code so far
function addTogether(...nums) {
let args = Array.from(arguments); //Turn arguments into an array
// console.log(Number.isInteger(args[1])) //Evaluates to false.
//Check for any non-integer arguments and return undefined if true.
// console.log(!args.every(arg => Number.isInteger(arg))); //Evaluates to true.
if(!args.every(arg => Number.isInteger(arg))){ //Statement executes, as this is true.
// console.log("undef"); //Prints to the console. If has executed as intended.
return undefined;
}
return true;
}
addTogether(2,[3]);
console.log(addTogether(2,[3])); //Returns undefined. Test is still not passed?
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Arguments Optional
Link to the challenge: