Tell us what’s happening:
I already feel a lot stupid because of the code I have written and I know there exists a really better way to make this challenge work but since I wrote it, I would love if someone can just help me make it work the right way. I will still give it few more hours but I need help with few things… If you understand my approach then please help me figure out few things missing in this thing but I don’t think it’s worth your time. Thanks!
Your code so far
function rot13(str) { // LBH QVQ VG!
var myArr = ['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'];
var arr = [];
var ar = [];
var bab = [];
for (var i = 0; i < str.length; i++) {
arr.push(myArr.indexOf(str[i]));
if (arr[i] >= 13){
ar.push(arr[i] - 13);
} else {
ar.push(arr[i] + 13);
}
bab.push(myArr[ar[i]]);
}
return bab.join('').replace(/M/g, " ");
}
// Change the inputs below to test
rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/caesars-cipher