# Credit Card Checker - not working

Hey there, having some trouble with my code. It seems to be returning an empty array and I’m not sure why…help please!

function validateCred(arr) {
const doubles = ;
let sum = 0;
for (let i = 15; i >= 0; i–) {
let start = arr[i];
if (i % 2 === 0) {
start *= 2
if (start > 9) {
start -= 9;
}
}
doubles.unshift(start);
}
return doubles;
sum += start;
if (sum % 10 === 0) {
return true;
}
}

function findInvalidCards(arr) {
let check = ;
for (let j = 0; j < arr.length; j++) {
if ((validateCred(arr[j])) === false) {
check.push(arr[j]);
}
}
return check;
}

This may not be the problem, per se, but it is going to be an issue down the road. The program needs to be able to check any length between 12 and 20 numbers.

I think I’ve figured out that the first function, validateCred is returning them all as false. Can someone help me out? I can’t figure out why.

``````function validateCred(arr) {
const doubles = [];
let sum = 0;
let start = undefined;
for (let i = (arr.length - 1); i >= 0; i--) {
if (i % 2 === 0) {
start *= 2
if (start > 9) {
start -= 9;
}
}
doubles.unshift(start);
}
sum += start;
if (sum % 10 === 0) {
return true;
} else {
return false;
}
}
``````

Let’s break out of the program and work exclusively on finding the right elements to double, regardless the length. That could take some thought so build that functionality by itself, in a repl.it or other sandbox.

• takes an array of undefined length
• doubles every second element from the right

Just return the array at this time so we can see which ones have doubled. Their values don’t matter so long as it is the correct elements. Test with any inputs from the sample set. It won’t matter. The returned array should always have the last value the same as before.

Something to consider… When the length is even, the first element gets doubled, and when odd, the second element gets doubled. Knowing this we no longer need to think of reversing the array. Work with it as it came in. Think of a way to set this up and you’re half the way there.