代码没有绕过第一个 "if" 语句

code is not bypassing first "if" statement

有人可以深入了解为什么我的代码没有绕过第一个“if”语句吗?我正在编写应该创建密码的代码。如果字母的 unicode 不大于 97 或小于 122,则应该按原样简单地推送 unicode。

// Write class below
class ShiftCipher{
  constructor(shift){
    this._shift = shift;
  }
  encrypt(str){
    let newStr = str.toLowerCase();
    let strArr = [];
    let newStrArry = [];
    let extraNum = 0;
    let bigArr = [strArr, newStrArry]
    for(let i = 0; i < newStr.length; i++){
      strArr.push(newStr.charCodeAt(i));
      if(newStr.charCodeAt(i) > 97 || newStr.charCodeAt(i) < 122) {
        if(newStr.charCodeAt(i)+this._shift > 122){
          extraNum = (newStr.charCodeAt(i)+this._shift) - 122;
          extraNum += newStrArry.push(96+extraNum);
          console.log('a');
          } else {
          newStrArry.push(newStr.charCodeAt(i)+this._shift);
          console.log('b');
          console.log(newStr[i]);
          }
      } else {
        newStrArry.push(newStr.charCodeAt(i));
        console.log('c');
      }
    }
    return bigArr;
  }
}
const mySymbol = new ShiftCipher(4);
console.log(mySymbol.encrypt('<3'));

每个可能的数字都满足条件 newStr.charCodeAt(i) > 97 || newStr.charCodeAt(i) < 122(即任何不大于 97 的数字都必须小于 122)。因此,没有任何输入会进入您的 else 子句。

我假设您希望 if 条件只接受 97 到 122 之间的 unicode。如果是这样,那么您需要将条件更改为 newStr.charCodeAt(i) > 97 && newStr.charCodeAt(i) < 122.