Tell us what’s happening:
Hello, I’m working on Ceaser’s Cipher challenge for FCC and I have most the code down so far. The code is properly decoding the strings, however, I am having difficulty figuring out how to put the sentence together properly. For EX: my code prints FREECODECAMP for SERR PBQR PNZC and FORPIZZA for SERR CVMMN!. I am stuck as to how I can separate this properly with spaces in between the words and how to still include the proper punctuation at the end.
**Your code so far**
function rot13(str) {
//Key of Ceasers Cipher placed into an Object format
var code = {
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 newArr = str.split("");//converts str into an array of characters
var newStr =
//filters undefined items in array
newArr.filter(item => item!==undefined)
//map feature replaces letters with their valued keys deciphering the ROT13 string
.map(x => code[x])
//joins code back into a string
.join("");
return newStr;
}
console.log(
rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT."),
rot13("SERR PBQR PNZC"), rot13("SERR CVMMN!"), rot13("SERR YBIR?")
);
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
Challenge: Caesars Cipher
Link to the challenge: