Credit Card Checker

Hi there!

I am looking for some HINTS on the Credit Card Checker task.
This is my 3rd day breaking my head and googling, but I can’t seem to find what I am
looking for.

I would appreciate some hints to keep me going.
** I created a new post because I don’t want to see the answer.
I am looking for some guidance.

Thank you.


function validateCred(num){

// Creates copy of array
let arrCopy = num.slice();

// Remove last element of array
arrCopy.pop();

// Loop through every other element of the array
for (let i = arrCopy.length - 2; i > 0; i = i - 2) {

    let everyOther = arrCopy[i];
    let doubled = arrCopy[i]*2;

    

    // If multiplied element is greater than 9, substract 9.
    if (doubled > 9) {
      doubled = doubled - 9;
    }

}

}

validateCred(valid1);

//The array I am checking on.
const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8];

I would check the logic on your for-loop. Console.log arrCopy[i] for reference.
Doesn’t hurt to check if your slicing and popping is happening like you want either (to be safe).

1 Like