Credit Card Checker: findInvalidCards()

In my findInvalidCards function output is always coming array with valid and invalid cards i don’t know what’s the problem in my function.

const findInvalidCards = arrList => {

let invalid = ;

for(let x of arrList) {

if(!validateCred(x)) {




return invalid;



This is my code :


for(let i = 15; i >= 0; i--) {

I wouldn’t hard-code the length of the array, use arr.length

But the fundamental problem is here:

let sum = 0;

sum is declared outside the function. Which means the numbers of the second card are added to the sum of the first card

the numbers of the third card are added to the sum of first and second card and so forth

This way, it becomes pretty random. We should get the sum of the numbers of each individual credit card. The sum shouldn’t include numbers from other credit cards

thanks i got the answer.