samedi 13 novembre 2021

How do I put a calculation inside a for loop with an if statement in between? What is the correct syntax?

With the use of my for loop looping backwards I want to get every other digit, double it and check if that number is bigger than 9. If the number is bigger than 9, I want to subtract nine from it. I want to do this in one function. Maybe use a built in function. This is what I got so far:

const validateCred = array => {
  for (let i = array.length -2; i >= 0; i = i -2 ) {
    let multiply = array[i] * 2;
    if (multiply > 9) {
      let minusNine = multiply -9;
    }
  }
};

Any suggestions would be a big help!

Aucun commentaire:

Enregistrer un commentaire