My code seems to have a bug where when I put certain letters such as “E” it bugs out and makes it a letter behind where it should be. Any suggestions? (I am not 100% done with the code, so I haven’t combined the characters.)
Your code so far
function rot13(str) { // LBH QVQ VG!
str = str.split('');
let n;
for(let i = 0; i => str.length; i++) {
n = str[i].charCodeAt(0);
n = n + 12;
if (n > 90) {
n = (n - 90) + 65;
}
console.log(String.fromCharCode(n))
str[i] = String.fromCharCode(n);
}
return str;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Safari/605.1.15
.
Link to the challenge: