Here’s a link to the exercise I’m trying to work through: Credit Card Checker | Codecademy
I’m trying to solve the Credit Card Checker project on the Full-Stack Engineer Path, but keep getting ‘false’ as my return for both valid and invalid credit card numbers. I’m following the hint given to use the Free Formatter’s Luhn algorithm implementation, but I’m not sure where I’m going wrong. I tried logging the newArr[i] values as well as the sum values and they seem fine, but maybe I’m missing something?
Any help would be greatly appreciated. Thank you!
function validateCred(array) {
let newArr = array.slice(0, array.length-1);
const arrEndNum = array[array.length-1];
newArr = newArr.reverse();
for(let i = 0; i < newArr.length; i++) {
if(i % 2 === 1) {
newArr[i] *= 2;
}
if(newArr[i] > 9) {
newArr[i] -= 9;
}
}
let sum = arrEndNum;
for(let i = 0; i < newArr.length; i++) {
sum += newArr[i];
}
if(sum % 10 === 0) {
return true;
} else {
return false;
}
}