Https://www.codecademy.com/practice/projects/credit-card-checker

hey everyone, please I’d like to know why one of these functions works and the other doesn’t. And they are meant to do the same thing

https://www.codecademy.com/practice/projects/credit-card-checker

they are supposed to return an array of invalid cards when being run;

this works:

const findInvalidCards = (cardB) => {
  let invalids = [];
  cardB.forEach(card =>{
    let status = validateCred(card);
    if(status===false){
      invalids.push(card);
    }
  });
  return invalids
}
console.log(findInvalidCards(batch))

This doesn’t

const findInvalidCards = (cardB) => {
  let invalids = [ ];
  for(i = 0; i < cardB.length; i++){
    let status = validateCred(cardB[i])
    if( status === false){
      invalids.push(cardB[i]);
    };
  };
  return invalids
}

console.log(findInvalidCards(batch))

https://www.codecademy.com/practice/projects/credit-card-checker

I don’t have access to the project so I’m not sure but try to log what card or cardB[i] is, and then log
status

is validateCred a function you wrote or given to you by codecademy?

shorter code:

const findInvalidCards = cardB => {
     return invalids.filter(card => !validateCred(card));
}