Credit Card Checker

My code for the first step, validateCred, seems to work fine on its own. I ran it with each of the given arrays and it returned the expected results. On the next step (findInvalidCards), though, the same function returns different results. In both cases, I logged each array to make sure the right numbers were running. It appeared that the correct numbers were being run, but for some reason the result is ‘valid’ in one case and ‘invalid’ in the other. Any help would be appreciated. Here’s the code:

let sumTot = 0;
let cardNum;
let finDig;

const validateCred = (a) => {
 finDig = a[a.length -1];
 //console.log(finDig);
 cardNum = a.slice(0, -1);
 //console.log(cardNum);
 for (let i = cardNum.length -1; i >= 0; i -= 2) {
   //console.log(cardNum[i]);
   if (cardNum[i] < 5) {
     sumTot = sumTot + (cardNum[i] * 2);

   } else if (cardNum[i] >= 5) {
     sumTot = sumTot + ((cardNum[i] * 2) - 9);

   } 
 }
   for (let i = cardNum.length -2; i >= 0; i -= 2) {
     sumTot = sumTot + cardNum[i];
 } 
   
 sumTot = sumTot + finDig;
   //console.log(sumTot);
   if (sumTot % 10 === 0) {
     return 'valid'
   } else {
     return 'invalid';
   } 
};

If I run this on “Invalid4” on its own, it returns invalid. In the next step, when I run this code:

et invalidCards = ;

const findInvalidCards = (b) => {
  for (let j = 0; j < b.length; j++){
   //console.log(b[j]);
   console.log(validateCred(b[j]));
  } 
};

findInvalidCards(batch);

It returns ‘valid.’

sumTot = sumTot + finDig;
//console.log(sumTot);
if (sumTot % 10 => 0) {
return ‘valid’
} else {
return ‘invalid’;
}
};

I changed === to =>. Try running it now. I’m new to coding. :upside_down_face: :upside_down_face: :upside_down_face: