jeudi 31 mars 2016

Javascript for loop with if statement not reaching the else if statement

why wont this reach the else if and return (i + 0) / 2? Also, why wont the alert give me i + 0 for a 2 digit value? (ie: 10, 20, 30, 40, etc. Any help would be appreciated.

var key= "OSN0MSA9991UNAAM8ELDPBD9F57BD6PU6BVBN54CDLEGDSUSNS";
var x = 0;
if (key[20] != "P" || key[18] != "P") {
 x = 0;
 for (i=0;i<10;i++) {
  if (key[26] == i) {
   x = i + 0;
   alert(x);
  }
 };
} else if (key[20] == "P") {
 for (i=9;i>-1;i--) {
  if (key[26] == i) {
    x = (i + 0) / 2;
   alert(x);
  }
 };     
};

Aucun commentaire:

Enregistrer un commentaire