For loop in JavaScript

Hello there,

I am creating a simple webpage for a Caesar Cipher.
I wrote the Cipher in Object-Oriented.

Something is wrong with a method though. Im not exactly sure but when I shift anything other than A, the encryption is wrong.

encrypt() {
      for (let i = 0; i < this.text_length; i++) {
        let char = this.plain_text[i].toUpperCase();
        if (char === " ") {
          this.encrypted_string += char;
        } else {
          let location = this.alphabet.indexOf(char);
          let new_location = (location + this.shift) % 26;
          this.encrypted_string += this.alphabet[new_location];
        }
      }
      return this.encrypted_string;
    }

As you can see in the image. B plus 1 shouldnt be L
caesarcipher.jpg
Was this page helpful?