Nested else-if not working (Caesar's Cipher)

Nested else-if not working (Caesar's Cipher)
0

#1

So currently working on the Caesars Cipher and have run into a problem:

for(i=0; i<uniStr.length; i++){     
    if(uniStr[i] !== first13.indexOf(uniStr[i])){
      translated = second13.indexOf(uniStr[i]);
      uniStr[i] = first13[translated];
     }else if (uniStr[i] !== second13.indexOf(uniStr[i])){
     a = first13.indexOf(uniStr[i]);
      uniStr[i] = second13[a];
    }
 }

When I run this the else if doesn’t work. The first one works fine, but can’t seem to get the second one to work. Even if I put it in an else{ } statement.

Edit:

This code seems to work :

for(i=0; i<uniStr.length; i++){ if (first13.indexOf(uniStr[i]) > -1){ a = first13.indexOf(uniStr[i]); uniStr[i] = second13[a]; }else if (second13.indexOf(uniStr[i]) > -1){ translated = second13.indexOf(uniStr[i]); uniStr[i] = first13[translated]; } }


#2

It sounds like your if condition is always evaluating to true.


#3

Wow thanks!! I am not sure why but that gave me a whole different way of looking at it and I think I fixed it!