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]; } }