Issue with credit card checker project

Hi everyone, i am currently stuck on the first step of the credit card checker project.
Here is my code:

Every single array that i put into my function returns false and i don’t know why so i wouldn’t be against a nod in the right direction. Sorry if my code is bad i’m still pretty new to this.

this condition:

if (i % 2 !== 0){

is the wrong way around. You are currently doubling every uneven/odd digit. You should double every even digit

i did the change you suggested but now i have another problem. Every function return true or false as it should except for invalid2 and invalid3 who returns true when they should return false… any hint?

EDIT: i was going too fast, things are working correctly now

I have another problem, valid3 returns false because it is 15 numbers long instead of 16 and (i % 2 === 0) returns true because my for is loop starting at array.length - 1 (which here becomes 14 instead of 15 for every other array), however i have absolutely no clue as to correct this, do you have a hint?

Could you please post an updated version of your code?

Here it is, i commented out the end because i am still working on step 5

I would start by placing this:

let invArr = [];

inside the body of your findInvalidCard function. If you don’t, the array will contain data from multiple function calls. also, you could use const.

if a number is on a even or uneven index should be determined from the left hand side. So you need to tweak this condition:

if (i % 2 === 0){

that this is done from the left hand side. We could use the .length for this

so the first iteration of the loop (when i is at highest) we could use the length - 1 to make zero, to check the index

“we could use the length - 1 to make zero, to check the index”

sorry i don’t get what you mean by this, isn’t this what i’m already doing since in the first iteration of the loop i is already equal to array.length - 1 since i set my loop to start at let i = array.length -1? so the highest i wil already always be array.length - 1?

lets say we have a list with 5 elements:

['a', 'b', 'c', 'd, 'e']

the last element in the array (e), is at an odd/uneven position. Yet the index is even (4).

so doing i % 2 == 0 won’t suffice

The index you are using is the array’s index for the item. For the card validation the index numbers should be reversed because it should go from right to left not left to right.


arr = [0, 1, 2, 3, 4, 5];
       5  4  3  2  1  0 // index for card validation