Credit Card Checker Help

How in this challenge are we accounting for varying lengths of the input arrays? In my head the only real consideration is whether it is an even or odd length, e.g., 15 or 16 digits. From there I figured I would have the function choose what to do based on whether the index was even or odd. From there I came up with the below. It says even the valid numbers are invalid so it’s not working. Is there a way to fix this code to work correctly or am I down the complete wrong path?

Your idea is correct, so you’re not on the wrong path. The implementation is just not correct yet, so the condition

(this.checkMeth === true)

is never true. It’s always the else code block that is executed.
That has 2 reasons:

  1. You declare the variable in a seperate scope, so it is unreachable in the condition:
if (arr.length % 2 === 0){
    let checkMeth = true
}

You can use the ternary operator instead.

let checkMeth = arr.length % 2 === 0;
  1. You’re within an ordinary function. So you don’t have to reference the variables with this keyword:
(this.checkMeth === true)

Write

if (checkMeth === true)

instead.

THANKS!!! THIS WAS THE KEY!!! I originally had it set to boolean true rather than the expression and just threw in a “this.” as a shot in the dark because it was giving me an error saying checkMeth was undefined in that scope(at least i thought thats what the error was). not sure why it seems to access checkMeth with no issue now though…

Update: I understand the scope issue with original declaration of checkMeth