JavaScript Algorithms and Data Structures Projects - Caesars Cipher

Hi guys, I’m new to coding and have been doing the courses on this website for the past couple months, I’ve started my final coding challenges for JavaScript and would like your opinion on the way I solved this challenge if it is good or not.

I have added a spolier tag as this solutions passed the criteria.

function rot13(str) {
 const shiftedAlphabet = 'NOPQRSTUVWXYZABCDEFGHIJKLM';
 let strArray = str.toUpperCase().split('');
 const regex = /[a-zA-Z]/;
 let result = '';

 for(let i = 0; i < strArray.length; i++){
   if(regex.test(strArray[i]) === true){
       result += normalAlphabet[shiftedAlphabet.indexOf(strArray[i])];
   else if(regex.test(strArray[i]) !== true){
      result += strArray[i];
 return result;
console.log(rot13("SERR PBQR PNZC"));
   **Your browser information:**

User Agent is: Mozilla/5.0 (Linux; Android 12; SM-X906B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: JavaScript Algorithms and Data Structures Projects - Caesars Cipher

Link to the challenge:

Good work getting a passing solution!

A few notes

You don’t need an else if, only an else. If the condition is not true, then it is automatically false.

You can avoid the regex and the two long strings if you use the character codes.

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