Roman Letter Converter

by Vanessa RC

JavaScript

function rot13(str) { 
  str.split('')
  
  var newArrWord = [],
      word;

  for (var i in str){
    
    if(str[i] === " "){
      newArrWord.push(str[i]);
    }
    else if (str[i].match(/^[a-zA-z]/) === null){
      newArrWord.push(str[i]);
    }
    else if(str.charCodeAt(i) + 13 > 90 ){
      newArrWord.push(String.fromCharCode(65 + str.charCodeAt(i) - 91 + 13));
    }
    else {
      newArrWord.push(String.fromCharCode(str.charCodeAt(i) + 13));
    }
    
     word = newArrWord.join('');
  
  }
    console.log(word);

  return word  
  };

rot13("SERR PBQR PNZC");// should decode to "FREE CODE CAMP"
rot13("SERR CVMMN!");// should decode to "FREE PIZZA!"
rot13("SERR YBIR?");// should decode to "FREE LOVE?"
rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.");// should decode to "THE QUICK BROWN DOG JUMPED OVER THE LAZY FOX."