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: