Challenge link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher
for challenge guide: freeCodeCamp Challenge Guide: Caesars Cipher
Solution
function rot13(str) {
let newStr = [];
let letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
for(let i = 0; i < str.length; i++){
(/\W/.test(str[i]))
? newStr.push(str[i])
: (letters[letters.indexOf(str[i]) + 13])
? newStr.push(str[i].replace(str[i], letters[letters.indexOf(str[i]) + 13]))
: newStr.push(str[i].replace(str[i], letters[letters.indexOf(str[i]) - 13]))
}
return newStr.join("");
}
Tried doing the challenge without String.charCodeAt() or String.fromCharCode() hope this helps.