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.
spoiler
function rot13(str) {
const shiftedAlphabet = 'NOPQRSTUVWXYZABCDEFGHIJKLM';
const normalAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
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/104.0.0.0 Safari/537.36
Challenge: JavaScript Algorithms and Data Structures Projects - Caesars Cipher
Link to the challenge: