vendredi 22 février 2019

If statement works weird javascript

function checkLetter(nr) {
  passArr = Array.from(pass);
  for (i = 0; i < 25; i++) {
    if (passArr[i] === alfabet[nr]) {
      document.querySelector("#let" + nr).style.background = "green";
      vpass[i] = alfabet[nr];
      password.innerHTML = vpass;
    } else {
      document.querySelector("#let" + nr).style.background = "red";
    }
  }
}

Can u explain me why does this two rows:

vpass[i] = alfabet[nr];
password.innerHTML = vpass;

Work exactly as i want that means it only changes the password when i click on right letter.

But background changes to red whatever letter i click. (every style i put to ELSE work on every letter but styles in IF work fine).

Aucun commentaire:

Enregistrer un commentaire