decided to do mine before watching the class, i looked at converting the alphabet to integer value and then looping with a +13 and back to a character but decided on hard coding in it an array was faster and less complicated.
non-alphabetic characters (i.e. spaces, punctuation) etc didn’t pass through so i added them to the array.
function rot13(str) {
const caesar = {
A: 'N',
B: 'O',
C: 'P',
D: 'Q',
E: 'R',
F: 'S',
G: 'T',
H: 'U',
I: 'V',
J: 'W',
K: 'X',
L: 'Y',
M: 'Z',
N: 'A',
O: 'B',
P: 'C',
Q: 'D',
R: 'E',
S: 'F',
T: 'G',
U: 'H',
V: 'I',
W: 'J',
X: 'K',
Y: 'L',
Z: 'M',
" ": " ",
"!": "!",
"?": "?",
".": "."
};
var code = "";
for (let i = 0; i < str.length; i++) {
code += caesar[str[i]];
}
return code;
}
rot13("SERR PBQR PNZC");
console.log(rot13("SERR CVMMN!"));