[Help needed] Valid cards not returning true

Hello. I’m having trouble getting the credit card checker (https://www.codecademy.com/practice/projects/credit-card-checker) to work. I was using the valid cards array for testing and it is returning that they are invalid. The only one that returns true is the one that was in the visual outlines step (array6). Could someone please help me? I don’t know what I’m doing wrong.
Here’s the code: https://gist.github.com/Mystixc/6cf1fd6b587a8591a38adc25cd6fc879
Thank you.


So, to implement the Luhn algorithm, you need to start from the end of the card number array, skip the last digit, and perform the doubling & subtracting 9 (when necessary) on every other digit. Could you explain the logic behind this:

if ((i - (arr.length - 1)) != 0)

How does that line of code isolate every other digit?

1 Like

Hey! Thank you for replying. I forgot to update this but after asking someone I realized I was not really understanding what I had to do. I thought that the only digit that was not supposed to be doubled was the last digit but I figured it out now. Thank you so much for the help!

1 Like