Need help with the rot13 project

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 :slight_smile:

  **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:

Hi there. You do indeed almost have it solved. You just need a way to check if a character is not in your alphabet array, so that you can just pass them on as they are. I recommend looking into Array.includes() to solve that problem:

Here’s the relevant documentation

Once you’ve solved it, I would recommend looking over your solution again, asking yourself if there are maybe some steps you’ve taken that you didn’t need to take, that might make the function more concise and human-readable. I’ve found this is a good exercise as I practice algorithms and learn more about best practices.

Good luck, and great work so far!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.