Credit Card checker - card validator issue

Hi all. I have an issue with the card checker project and I don’t know why… I’ve tried every single thing to figure it out and I just can’t. Maybe someone can give me some advice?
Essentially my code for doing the Luhn Algorithm is below. It seems to work and pick up every invalid number, EXCEPT Valid No 3… It somehow manages to slip through the cracks…
Can i get some help please? :slightly_smiling_face:

const validateCred = (array) => {
    
    let arraySum = [];
    for (let i = 15; i >= 0; i--) {
        if (i%2 !== 0) { 
            arraySum.push(array[i]) } else {
            if ((array[i] * 2) > 9) {
                arraySum.push((array[i] * 2) - 9);
            } else {
                arraySum.push((array[i] * 2));
            };
        };
    };
const initialValue = 0;
const sumSum = arraySum.reduce((accumulator, currentValue) => accumulator + currentValue,  initialValue);
if (sumSum % 10 === 0) {
    return true;
} else {
    return false;
};
};

Credit card numbers can vary in the number of digits. If we set a fixed number then we miss all the other possible cases.

Thanks for you answer, I have changed that. I also managed to notice some other issues in the code regarding parity of card numbers and managed to get this to work.
Thanks once more

1 Like

Don’t delete the thread, please. Leave it for others to find who run into the same problem.