Credit Card Checker Help


I have been working on credit card checker project and this is my code -

I have tried to do it my way. For the first bit I tried to create a reverse loop. Its not taking the value given. It is not logging the final list either.

Best Regards

Line 52 has a typo
for (let k=0; k<batch.legnth; k++){

that should be length not legnth

Hello, @trishnapandey0880521, and welcome to the forums.

First of all:

for (let i=15; i>=0; i--){

That won’t work for several of the numbers. Not all of the credit card numbers have 16 digits. Also you need to perform the doubling and possible subtracting of 9 on every other digit after skipping the last digit. Using the even-ness or odd-ness of the digit’s index in the array to determine which numbers to perform those actions on won’t work either on numbers with an odd number of digits.

You might need to re-consider your approach.

Also, I’d get away from using var. Use let or const. None of your variables require function scope. Block scope is sufficient for all of them.

1 Like