mardi 7 septembre 2021

code is not bypassing first "if" statement

Could someone provide insight on why my code is not bypassing the first "if" statement? I am writing code that is supposed to create a cipher. If the letter's unicode is not greater than 97 or less than 122, it is is supposed to simply push the unicode as it is originally stated.

// 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'));

Aucun commentaire:

Enregistrer un commentaire