Credit Card Checker

Hi,

I am stuck in the creditcard checker. I don’t know where to start and it’s overwhelming. I am trying out some things and I know I need to use: reverse(), a for loop and if statement. Can someone help me with this?

Ofcourse I can search the forum for solutions but then I still don’t get it and someone else’s code is overwhelming to me. :relaxed:

This is what I have for now.

const validateCred = (valid1) => {
  let array = valid1;
  let reversedArray = array.reverse();
  for(i = 0; i <= reversedArray.length; i++) {
    if(i === i *= 2) {
      return ...;
    } else {
      return 'Invalid'
    }
   }
};

console.log(validateCred());

Thank you in advance.

Rosita

Hi,

This statement will cause issues:

if(i === i *= 2)

since you’re trying to do two things at once (comparison and assigment). Just remember that i *= 2 means that you want i assigned a new value that is itself multiplied by 2.

With loops it’s always useful to have console.logs to explicit track what’s going on inside the loop.

I’ve just completed this task yesterday so its still fresh in my mind.

Personally i’ve done 2 for loops
eg
1st loop may start… i=0 and increases by i+=1 (that means it will skip one element then iterate the next.
2nd loop will start i=1 and again increase i+=1
the order the elements will be different but I don’t see (and it didn’t) effect the final results.

let me know if you want me to share that part of my code. It’s a little different but I’m sure you’ll see it :smiley: