Tell us what’s happening:
it seems that i’m on the right track to finish this project, yet i can’t understand how can i add spaces and other symbols to the rot13 function.
i can add them to the alphabet variable but i think it needs to be more dynamic.
Thanks for the help in advanced
**Your code so far**
function rot13(str) {
// list of all alphabet letters
let 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"];
// conver all letters to uppercase letters
let alpha_upper = alphabet.map(item => item.toUpperCase() );
// split the string argument (str)
let arrOfWordsstr = str.split("");
let afterRot = "";
// iterate over the array and add 13 to each word
let afterChange = arrOfWordsstr.map(item => {
// checking if the character is not a letter
// check if the item exceeds the array & the array should continue from the beginning
if(alpha_upper.indexOf(item) >= 0){
if(alpha_upper.indexOf(item) + 13 >= alpha_upper.length){
// ------ alpha_upper[alpha_upper.indexOf(item) + 13] ------
afterRot += alpha_upper[(alpha_upper.indexOf(item) + 13) - alpha_upper.length];
} else {
afterRot += alpha_upper[alpha_upper.indexOf(item) + 13];
}
}
});
console.log(afterRot);
// return str;
}
rot13("SERR PBQR PNZC");
**Your browser information:**
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0
Challenge: Caesars Cipher
Link to the challenge: