Hey Guys!
I wonder if there’s anyone trying to figure out step 7 - Create a function that will convert invalid numbers into valid numbers? Here’s my code but unfortunately I’m getting an error. Can anyone help me with this?
//7
function covertIntoValid (invalidCard) {
let checkForModulo = 0;
let lastElement = arr[arr.length - 1];
let newArray = arr.slice(0, -1);
let modulo = (checkForModulo + lastElement) % 10
newArray.reverse();
for (i = 0; i < arr.length; i += 2) {
newArray[i] *= 2;
if (newArray[i] > 9) {
newArray[i] -= 9;
}
checkForModulo += newArray[i];
}
for (j = 1; j < newArray.length; j += 2) {
checkForModulo += newArray[j];
}
if (!modulo === 0) {
let newLastDigit = (10 - modulo);
return arr.splice(-1, 1, newLastDigit)
}
return arr
}