Challenge Project: Credit Card Checker | Codecademy
I’m struggling with Javascript in general. These last few lessons have had me working at a snail’s pace. And now I’m stuck on this project. Any help would be super appreciated!
const validateCred = arr => {
for (let i = arr.length - 1; i >= 0; i--) {
let val = arr[i];
if (i % 2 === 0) {
continue;
}
val *= 2;
console.log('ARRI*2: ' + val);
if (val > 9) {
val -= 9;
console.log('ARRI-9: ' + val);
}
let total = 0;
for (let j = 0; j < arr.length; j++) {
total += val;
console.log('TOTAL: ' + total);
return total % 10 === 0;
}
}
};
console.log(validateCred(valid1));
// const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8];
console.log(validateCred(invalid1));
// const invalid1 = [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5];
console.log(validateCred(mystery1));
// const mystery1 = [3, 4, 4, 8, 0, 1, 9, 6, 8, 3, 0, 5, 4, 1, 4];
This is my code. If y’all could pick it apart and tell me all the reasons why it’s not working, that would be great. I feel like I have a small knowledge gap when it comes to Javascript functionality that is having a huge impact on my current progress.
Code returns this to console:
##
Output-only Terminal
Output:
ARRI*2: 16
ARRI-9: 7
TOTAL: 7
false
ARRI*2: 10
ARRI-9: 1
TOTAL: 1
false
ARRI*2: 2
TOTAL: 2
false
// KNOWN ISSUES:
// it should be iterating through the rest of the numbers in each array
// the first one should be true. the last one is a mystery of whether it is true or false
Thank you!!