Tell us what’s happening:
Hey guys,
Im trying to do the Ceasar’s Cipher JS project and I’m stuck on one of the steps. Im trying to parse through the alphabet array with the encryption array and return the index from the alphabet array of the elements that match. However my code is not working as intended. Any advice/feedback on my code and where I’m making a mistake would be appreciated.
Thanks,
Your code so far
function rot13(str) {
const alphabet = ['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'];
let encryption = str.split("");
let encryptLocation = [];
for (var i in encryption){
if (alphabet.indexOf[encryption[i]] > -1){
encryptLocation.push(alphabet[i].indexOf());
}
}
console.log(encryption, encryptLocation);
return str;
}
rot13("SERR PBQR PNZC");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Challenge: JavaScript Algorithms and Data Structures Projects - Caesars Cipher
Link to the challenge: