Caesars Cipher First Case issue

What’s happening:
Hey everyone, Ive gotten so close to solving this. It passes 3/4 test cases. The one it doesnt pass is the first one. I don’t know why it does not look at the third word, can someone see whats going one with it?

thanks for the help

My code so far


function rot13(str) {
let alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
str = str.split('');
let result = '';
let word = "";

for(let i = 0; i<str.length; ++i){
  let index = alpha.indexOf(str[i]);
  if(isLetter(str[i])){
    word += alpha[(index + 13) % 26];
  }
  else{
    result += word;
    result += str[i];
    word = "";
  }
}
console.log(result)
return result;
console.log(result);

}

function isLetter(str) {
return str.length === 1 && str.match(/[a-z]/i);
}

rot13("SERR PBQR PNZC");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.165.

Challenge: Caesars Cipher

Link to the challenge:

Hello and welcome to the FCC community~!

I believe I see the error. Your if else conditions only push the translated word to the result string when they run into a non-alphabet character. So for the other three tests, they push the last word because of the punctuation. But for the first test, they don’t push the last word because there is nothing at the end of the string that triggers the else condition.

1 Like

Cheers carrigan, I see the issue now, I’ll get it sorted. Eagle eyes right there my friend

1 Like