Credit Card Checker 'findInvalidCards'

Hi Guys,
So I’m struggling with part 4 of the Credit Card Checker project. I am trying to loop through the nested array “batch” and perform the validateCred function on each element of the array. I have chosen forEach to do this. If the validateCred function returns false, I push that element into the empty array “invalidArray”. My problem is that when I log “invalidArray”, I get a continuous array with each of the invalid cards rather than a nested array which lists the invalid cards as their variable names. I have included my code below:

let invalidArray =[];
const findInvalidCards = (nestArray) => {
    nestArray.forEach(element => {
        let cardStatus = validateCred(element);
        if (cardStatus === false){
            invalidArray.push(element);
        }
    });
    console.log("Invalid cards include:" + invalidArray);
};
findInvalidCards(batch);

I hope this makes sense and someone can hep me! Thanks in advance!

Hello @shannonlouiseguild61. Welcome to the forum.

I’m not sure what you’re asking. Could you post an example of what your output looks like versus what you are wanting it to look like?

EDIT:
I just looked at the project (almost finished), and I see what you’re saying. You don’t actually need the variable name associated with each card number array. If you have an array containing the arrays of invalid numbers: [[################],[################],[################]], then you’re doing fine. You could write a function to determine which of the original variable names go with each invalid card number, but that would be outside the scope of the project.

2 Likes

Invalid cards are determined by their card number not their variable name. You are perfectly within the scope of the assignment. Onto the determine company function :wink: .

But I guess to challenge yourself you could re-write the two functions to take on objects with key-value pairs and present an array of objects. Have fun!

2 Likes

Thank you for this I really appreciate your help!

Thank you very much! Glad to know I’m somewhat understanding how to do it :slight_smile:

1 Like