# Ceasars Cipher challenge, can't get the code to work perfectly

**URL:** <https://forum.freecodecamp.org/t/ceasars-cipher-challenge-cant-get-the-code-to-work-perfectly/4749>\
**Category:** General\
**Created:** [May 26, 2016, 10:11am UTC](https://forum.freecodecamp.org/t/ceasars-cipher-challenge-cant-get-the-code-to-work-perfectly/4749 "2016-05-26T10:11:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wisdomabioye](https://avatars.discourse-cdn.com/v4/letter/w/82dd89/32.png) [@wisdomabioye](https://forum.freecodecamp.org/u/wisdomabioye)\
**Post date:** [May 26, 2016, 10:11am UTC](https://forum.freecodecamp.org/t/ceasars-cipher-challenge-cant-get-the-code-to-work-perfectly/4749/1 "2016-05-26T10:11:38Z")

</div>

This code is working but non-alphabetic characters are removed. Someone help please.

```
function rot13(str) { // LBH QVQ VG!
var strUpper = str.toUpperCase(); 
var res, i;
var final = "";
for(i=0; i < strUpper.length; i++){
        res = String.charCodeAt(strUpper[i]);
        if (res>=65 && res<=77){
          res+=13;
          final += String.fromCharCode(res);
        }
        else if (res>=78 && res<=90){
          res-=13;
        final += String.fromCharCode(res);}  
      }
      return final;     
    }
    // Change the inputs below to test
    rot13("LBH QVQ ?VG");
```

---

<div class="post-metadata">

**Author:** ![wisdomabioye](https://avatars.discourse-cdn.com/v4/letter/w/82dd89/32.png) [@wisdomabioye](https://forum.freecodecamp.org/u/wisdomabioye)\
**Post date:** [May 26, 2016, 10:50am UTC](https://forum.freecodecamp.org/t/ceasars-cipher-challenge-cant-get-the-code-to-work-perfectly/4749/2 "2016-05-26T10:50:20Z")

</div>

I finally got it working by adding this:

```
  else {
          final += strUpper[i];
        }

```

so happy to complete this challenge. Thanks to freecodecamp.

---

<div class="post-metadata">

**Author:** ![thiagodebastos](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/thiagodebastos/32/165193_2.png) [@thiagodebastos](https://forum.freecodecamp.org/u/thiagodebastos)\
**Post date:** [June 26, 2016, 10:15am UTC](https://forum.freecodecamp.org/t/ceasars-cipher-challenge-cant-get-the-code-to-work-perfectly/4749/3 "2016-06-26T10:15:51Z")

</div>

It was definitely my facourite challenge so far!

---

<div class="post-metadata">

**Author:** ![adamShaleen](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/adamshaleen/32/159511_2.png) [@adamShaleen](https://forum.freecodecamp.org/u/adamShaleen)\
**Post date:** [September 2, 2016, 10:27pm UTC](https://forum.freecodecamp.org/t/ceasars-cipher-challenge-cant-get-the-code-to-work-perfectly/4749/4 "2016-09-02T22:27:32Z")

</div>

I’ve tried running this code exactly and I get the following error:

Uncaught TypeError: String.charCodeAt is not a function

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![CrowsVeldt](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/crowsveldt/32/66345_2.png) [@CrowsVeldt](https://forum.freecodecamp.org/u/CrowsVeldt)\
**Post date:** [September 16, 2016, 3:11pm UTC](https://forum.freecodecamp.org/t/ceasars-cipher-challenge-cant-get-the-code-to-work-perfectly/4749/6 "2016-09-16T15:11:36Z")

</div>

I hated this challenge! Granted it was my fault; I was on completely the wrong track, banging my head against a series of brick walls. Thanks for sharing your solution, just skimming through this thread made me realize my mistake and I went back and figured out how to make it work.

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 16, 2021, 5:29am UTC](https://forum.freecodecamp.org/t/ceasars-cipher-challenge-cant-get-the-code-to-work-perfectly/4749/7 "2021-01-16T05:29:44Z")

</div>

Closed on January 16, 2021, 5:29am UTC


