Caesars Cipher - Weird error in conditional

function rot13(str) { 
  for (i=0;i<=str.length-1;i++){
    if (str.charCodeAt(i)>=65 && str.charCodeAt(i)<=77){
      conv[i] = String.fromCharCode(str.charCodeAt(i)+13);
    }else if (str.CharCodeAt(i)>=78 && str.CharCodeAt(i)<=90){
      conv[i] = String.fromCharCode(str.charCodeAt(i)-26);
      conv[i] = str[i];
  conv = conv.join("");
  return conv;

When I used “||” in the conditions I got incorrect results and no errors. When I changed it to “&&” I got this error: str.CharCodeAt is not a function. How is this possible

When you changed your first if statement condition to &&, both conditions had to be true. When they both were not true, your else if statement conditions were evaluated. The problem is, there is no such string function called CharCodeAt which you attempted to use on str. Remember, JavaScript is case-sensitive, so you must make sure you use the correct capitalization for function and variables names.


Thanks! This kind of typos are so hard to spot sometimes…